#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <crypt.h>
int main(int argc, string argv[])
{
if(argc > 2){ printf("too many arguments\n"); return 51; }
if(argc < 2){ printf("too few arguments\n"); return 50; }
//if(strlen(argv[1]) > 4){ printf("Password is greater than 4 characters\n"); return 52; }
if(argc == 2) //make sure there are enough args
{
char hash_guess[] = "rofk";
//long long counter = 0;
//while(guess != argv[1]) //crypt(hash_guess, "50") != argv[1]) //while answer not correct
//{
for(int a = 65; a < 91; a++)
{
for(int b = 65; b < 91; b++)
{
for(int c = 65; c < 91; c++)
{
for(int d = 65; d < 91; d++)
{
for(int A = 0; A < 9; A = A + 5) //control if first is caps or not
{
for(int B = 1 ; B < 9 ; B = B + 5)//control if second is caps or not
{
for(int C = 2; C < 9; C = C + 5) //control if third is caps or not
{
for(int D = 3; D < 9; D = D + 5) //control if fourth is caps or not
{
hash_guess[0] = a;
hash_guess[1] = b;
hash_guess[2] = c;
hash_guess[3] = d;
hash_guess[A] = tolower(hash_guess[A]);
hash_guess[B] = tolower(hash_guess[B]);
hash_guess[C] = tolower(hash_guess[C]);
hash_guess[D] = tolower(hash_guess[D]);
printf("%s\n", hash_guess);
string cryptoguess = (crypt(hash_guess, "50"));
string input = argv[1];
if( cryptoguess == input ) { return 0; }
}
}
}
}
}
}
}
//}
//}
//string guess = crypt(hash_guess, "50");
//printf("%lli", counter);
}
}
}
我正在尝试制作一个程序,它通过每 4 个字母的单词,从 aaaa 开始到 ZZZZ。我完成了那部分。
部分作业是对其进行加密,如果加密与加密密码相匹配,那么您就知道您“破解”了他们的密码。当我比较我手动输入的加密密码和使用 crypt 函数出现的密码时,它们是相同的,但是在调试器中我看到它被计算机加密时是这样的:
"0x7ffff7dd9200 <_ufc_foobar+131200> "50k72iioeOiJU""
和我输入的正常显示
"0x7fffffffe34f "50k72iioeOiJU""
没有 _ufc_foobar 也是一样。有谁知道为什么会出现这种情况以及我该如何摆脱它?
最佳答案
您看到的奇怪垃圾是代码中可以忽略的内存地址偏移量的可视化。
当 GNU 指定 char *
是 crypt
函数的结果时,您在代码中使用 string
。
因此,您不能使用==
比较指向char
数组的指针,而是需要使用strcmp
C comparing pointers (with chars)
对于地穴,请参阅:http://www.gnu.org/software/libc/manual/html_node/crypt.html
关于c - 获取密码的隐窝是添加一些奇怪的 foobar 东西,所以它不等于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44939677/