私はここでかなり頭を掻いていて、解決策を見つけることができませんでした。 シンプルな4文字のパスワードを解読するために、このコードを書いています(下記のコードを参照)。私は、パスワードが正しく生成され、すべての可能性がAからZの文字のすべての組み合わせでテストされているが、ループは決して終わらないことがわかります。誰かが私に理由を教えてもらえますか?秘密のブルートフォースは決してループを終了しません
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <crypt.h>
int main(int argc, string argv[])
{
//check number of arguments
if(argc != 2)
{
printf("Usage: ./crack hash\n");
}
char str[5];
char salt[] = "..";
strncpy(salt, argv[1], 2);
string hash = argv[1];
string password = "....";
char pass[5];
//brute force loop
for(int i = 65; i < 123; i++)
{
str[0] = i;
for(int j = 65; j < 123; j++)
{
str[1] = j;
for(int k = 65; k < 123; k++)
{
str[2] = k;
for(int l = 65; l < 123; l++)
{
str[3] = l;
str[4] = '\0';
strcpy(pass, str);
password = crypt(pass, salt);
if (hash == password)
{
printf("%s\n", password);
break;
}
printf("\r%s", pass);
fflush(stdout);
}
}
}
}
}
で2つの文字列を比較したいので
if (hash == password)
はif(!strcmp(hash,password))
をする必要があります。他の人は続ける –すべての組み合わせを試しても終わらないようにしてください。たぶん、この質問はあまり言い表されていません。 – AlastairG
「文字列」タイプとは何ですか? – AlastairG