gpt4 book ai didi

c - 4 个字符破解速度很快,但添加第 5 个循环会减慢整个程序的速度

转载 作者:行者123 更新时间:2023-11-30 16:12:03 27 4
gpt4 key购买 nike

我正在为一个类编写一个程序,该程序通过在命令提示符处收集散列密码并将该散列与 crypt() 函数生成的散列进行匹配来破解 5 个字符 (aA-zZ) 密码。我的问题是添加第五个循环来破解 5 个字符的密码会减慢程序的停止速度,即使对于 1-4 个字符的密码也是如此,我必须取消。删除第 5 个循环可在一分钟内破解 1-4 个字符的密码。

我们只介绍了类中的基础知识,这在我的代码中进行了演示。因此解决方案必须符合此编码级别。

#include <cs50.h>
#include <stdio.h>
#include <crypt.h>
#include <string.h>

void printpass (string fst, string hsh1, string hsh);
/* prompt user for 1 cmd line argument */
int main(int argc, string argv[])

{
/* only allow 1 cmd line argument and return cmd line error
and exit if false */
if (argc != 2)
{
printf("Invalid request!\n");
return 1;
}
string hash = argv[1];
char slt1 = hash[0];
char slt2 = hash[1];
char salt[3] = {slt1, slt2, '\0'};
char alpha[52] = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";//upper & lowercase passwords only

for (int d = 0; d < 52; d++) //search for one character pw
{
char s1 = alpha[d];
char first1[2] = {s1, '\0'};
string hash0 = crypt(first1, salt);
printpass (first1, hash0, hash);

if (strcmp(hash0, hash) != 0)
for (int f = 0; f < 52; f++) //search for two character pw
{
char s2 = alpha[f];
char first2[3] = {s1, s2, '\0'};
string hash1 = crypt(first2, salt);
printpass (first2, hash1, hash);

if (strcmp(hash1, hash) != 0 || strcmp(hash0, hash) != 0)
for (int h = 0; h < 52; h++) //search for two character pw
{
char s3 = alpha[h];
char first3[4] = {s1, s2, s3, '\0'};
string hash2 = crypt(first3, salt);
printpass (first3, hash2, hash);

if (strcmp(hash2, hash) != 0 || strcmp(hash1, hash) != 0 || strcmp(hash0, hash) != 0)
for (int j = 0; j < 52; j++) //search for two character pw
{
char s4 = alpha[j];
char first4[5] = {s1, s2, s3, s4, '\0'};
string hash3 = crypt(first4, salt);
printpass (first4, hash3, hash);

if (strcmp(hash3, hash) != 0 || strcmp(hash2, hash) != 0 || strcmp(hash1, hash) != 0 || strcmp(hash0, hash) != 0)
for (int l = 0; l < 52; l++) //search for two character pw
{
char s5 = alpha[l];
char first5[6] = {s1, s2, s3, s4, s5, '\0'};
string hash4 = crypt(first5, salt);
printpass (first5, hash4, hash);

}
}
}
}
}
}

void printpass (string fst, string hsh1, string hsh) //compare hashes and print if true
{
if (strcmp(hsh1, hsh) == 0)
{
printf("%s", fst);
}
}

随着代码中的第五次循环,1-4 个字符的密码应在一分钟内完成。

最佳答案

4 个字符长的密码最多需要 7311616 (or 52^4)迭代破解,5个字符长的密码最多需要380204032 (or 52^5)迭代。

关于c - 4 个字符破解速度很快,但添加第 5 个循环会减慢整个程序的速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58438801/

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