gpt4 book ai didi

c - C 语言的基本暴力破解程序

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

我正在开发一个程序,该程序将加密的密码与使用相同 Salt 值加密的测试单词进行比较。 Salt 是 2 个字符的密码,用于在 crypt() 函数中进一步对输入进行卷积,并保存为加密密码的前 2 位数字。预期的结果是密码/盐组合被加密为与我正在寻找的密码相同的值——一个等效的密码。但是,Salt 无法正确打印,因为在从加密密码读取 2 个字符后,它会显示附加(不可读)信息。虽然程序运行时没有出现错误,但无论使用什么密码,它都会得到相同的结果,并且在编译时出现 2 个警告:

Crack1.c:54:27: warning: implicit declaration of function 'crypt' is invalid    in
C99 [-Wimplicit-function-declaration]
*decyphered = crypt(wordtest, salt);
^
Crack1.c:60:53: warning: comparison of array 'wordtest' not equal to a null
pointer is always true [-Wtautological-pointer-compare]
while(!memcmp(enc1, decyphered, (k + 2)) && wordtest != NULL);
^~~~~~~~ ~~~~
2 warnings generated.

运行时:

Test

Print encrypted text: 50zPJlUFIYY0o
Encrypted text: 50zPJlUFIYY0o
Salt value #0 = 5
Salt value #1 = 0
Full Salt: 50?Z?V?
Password: aA

Password: A&A

Password: A&NV

Password: A&NXM

Password:


Password: A&DwSOD

Password: A&BQVANT

我猜测盐问题正在影响 crypt() 函数。

源代码:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/*
This program take an encrypted input
before encrypting a host of strings
and comparing those encryptions to
the original input. All files read
from are to be kept in the same
folder.
*/

int main(int argc, char *argv[])
{

//Get and print text to be encyphered
printf("\nTest\n");
char enc1[50];
char salt[2];
char decyphered[50];
char filename[8][15] = {"two.txt","three.txt", "four.txt","five.txt","six.txt","seven.txt","eight.txt"};

char wordtest[10];
printf("\nPrint encrypted text: ");
scanf("%s", enc1);
printf("Encrypted text: %s\n", enc1);

//Fill salt
for (int i = 0; i < 2; i++)
{
salt[i] = enc1[i];
printf("Salt value #%i = %c\n", i, salt[i]);
}

printf("Full Salt: %s", salt);

//Run all possibilites and check result
FILE *fp;

for (int k = 0; k < 8; k++)
{
fp = fopen(filename[k],"r"); // opens files in read mode

if(fp == NULL)
{
perror("\nError while opening the file.\n");
exit(EXIT_FAILURE);
}

do
{
fgets(wordtest, k + 3, (FILE*)fp);
*decyphered = crypt(wordtest, salt);
if (memcmp(enc1, decyphered, (k + 2)))
{
printf("\nPassword: %s\n", wordtest);
}
}
while(!memcmp(enc1, decyphered, (k + 2)) && wordtest != NULL);


}

return 0;
}

任何帮助将不胜感激!

最佳答案

解决盐问题的最短解决方案是:

printf("Full Salt: %c%c", salt[0],salt[1]);

或者您可以定义salt[3]并设置salt[2] = '\0'然后使用 printf 打印 %s

关于wordtest != NULL warning ,当您分配wordtest时如char[10]那么您已经在堆栈中为该变量分配了空间,因此将其与 null 进行比较是不合理的,但您可能想测试 wordtest 的内容是否相同是否为空,可以通过以下方式完成:

strcmp(wordtest, "");

关于c - C 语言的基本暴力破解程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36671686/

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