gpt4 book ai didi

C:比较hash值好像消失了

转载 作者:太空宇宙 更新时间:2023-11-04 02:30:07 24 4
gpt4 key购买 nike

出于对神圣代码的热爱,我正在尝试比较哈希值以找到正确的密码。我得到一个散列作为命令行参数,然后我对从“a”到“ZZZZ”的单词进行散列,直到其中一个散列对匹配为止。

void decipher(string hash)
{
//Set the password, and the salt.
char pass[4] = "a";
char salt[] ="50";

//Compare the crypted pass againts the hash until found.
while (strcmp(hash,crypt(pass, salt)) != 0)
{
//Use int i to hold position, and return next char
int i = 0;
pass[i] = get_next(pass[i]);
tick_over (pass, i);

//Hardcode in a fail safe max length: exit.
if (strlen(pass) > 4)
{
break;
}
}
printf("%s\n", pass);
}

问题是当密码长度为 4 个字母时,它不会“捕获”正确的密码/比较。它适用于 1,2 和 3 个字母长的单词。

//Tick over casino style
string tick_over (string pass, int i)
{
//Once a char reaches 'Z', move the next char in line up one value.
char a[] = "a";
if (pass[i] == 'Z')
{
if (strlen(pass) < i+2)
{
strncat (pass, &a[0], 1);
return pass;
}
pass[i+1] = get_next(pass[i+1]);
//Recursively run again, moving along the string as necessary
tick_over (pass, i+1);
}
return pass;
}

//Give the next character in the sequence of available characters
char get_next (char y)
{
if (y == 'z')
{
return 'A';
}
else if (y == 'Z')
{
return 'a';
}
else
{
return y + 1;
}
}

它确实遍历了正确的词,正如我在调试中发现的那样。我试过移动

strcmp(hash, crypt(pass, salt)) == 0

除其他外,进入嵌套的 if 语句,但这似乎不是问题所在。 c 是否以某种方式“忘记”了命令行值?调试时哈希值似乎消失了:/请帮忙!

最佳答案

char pass[4] = "a"; 您正在定义一个 char 数组,它最多可以包含 3 个字符 + 空终止符。

这与您的“安全”测试不一致:if (strlen(pass) > 4)

strlen 为 4 时,由于空终止字符,数组已经覆盖了内存中的某些内容:未定义的行为

Quickfix:char pass[5] ...

关于C:比较hash值好像消失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44506916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com