gpt4 book ai didi

CS50 Pset 2.我的crack.c代码编译并运行,但不打印任何内容

转载 作者:行者123 更新时间:2023-11-30 19:28:29 33 4
gpt4 key购买 nike

我正在研究 Pset 2 hack.c,到目前为止,我已经设法了解了总体概念。但是,我的代码仍然不起作用。它编译并运行但不打印任何内容。

我不完全确定这里出了什么问题,我可能忽略了一些东西?

#include <stdio.h>
#include <cs50.h>
#define _XOPEN_SOURCE
#include <unistd.h>
#include <crypt.h>
#include <string.h>

char plaintext[4];
char salt [3];
string alphapool;
string newhash;

int main (int argc, string argv[]) {


if (argc != 2)
{
printf("Error: Input 2 command line arguments\n");
return 1;
}

else

{
alphapool = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./";
salt[0] = argv[1][0]; salt[1] = argv[1][1]; salt[2] = '\0';

//match a plaintext guess to an array in possibilities (alpha pool)
//for one letter

for(int i = 0; i < 26+26; i++)

{ //single letter
plaintext[0] = alphapool[i];
plaintext[1] = '\0';

newhash = crypt(plaintext, salt);

if ((strncmp(argv[1], newhash,13)) == 0)
{
printf("Match found, password is %s",plaintext);
return true;
}
}

for(int i = 0; i < 26+26; i++)

{//double letter
plaintext[0] = alphapool[i];

for(int j = 0; j < 26+26; j++)
{
plaintext[1] = alphapool[i];
plaintext[2] = '\0';

newhash = crypt(plaintext, salt);

if ((strncmp(argv[1], newhash,13)) == 0)
{
printf("Match found, password is %s", plaintext);
return true;
}

}
}

for(int i = 0; i < 26+26; i++)
{//three letter
plaintext[0] = alphapool[i];

for(int j = 0; j < 26+26; j++)
{
plaintext[1] = alphapool[i];

for (int k = 0; k < 26+26; k++)
{
plaintext[2] = alphapool[i];
plaintext[3] = '\0';
}

newhash = crypt(plaintext, salt);

if ((strncmp(argv[1], newhash,13)) == 0)
{
printf("Match found, password is %s", plaintext);
return true;
}

}

}
for(int i =0; i < 26+26; i++)
{
//four letter word
plaintext[0] = alphapool[i];

for(int j = 0; j < 26+26; j++)
{
plaintext[1] = alphapool[i];

for (int k = 0; k < 26+26; k++)
{
plaintext[2] = alphapool[i];

for (int l = 0; l < 26+26; l++)
{
plaintext[3] = alphapool[i];

}


newhash = crypt(plaintext, salt);

if ((strncmp(argv[1], newhash,13)) == 0)
{
printf("Match found, password is %s", plaintext);
return true;
}
}
}
}

return 0;

}
}

我希望生成的明文应该是生成与给定哈希匹配的哈希的值。

最佳答案

输出的字符串可能已被缓冲,您应该使用 fflush (参见手册页)在从程序返回之前强制将缓冲区写入终端中。

关于CS50 Pset 2.我的crack.c代码编译并运行,但不打印任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53907586/

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