我正在用 C 编写一个程序来破解基于 DES 的加密密码,它将密码作为参数并给我密码。
我所做的是通过用相同的盐(前 2 个字母)加密它们来尝试 500000 个单词,然后将其与 argv[1] (这是我要破解的加密密码)进行比较。我认为这被称为蛮力(尽一切可能)。无论如何,我的问题是,当我加密单词时,我得到了不同的加密(相同的盐和相同的密钥),正如您看到的那样,我打印了数字、单词和加密(只是为了检查它是否有效),您可以根据需要删除它们!
顺便说一句,我从某个网站获得了从文件中读取该行的代码,因为我是 C 新手,而且我还没有了解文件!
请温柔一点,我在这里真的很新:D,如果您对设计或代码有意见,请告诉我 :)!
顺便说一句,我正在学习 XHarved 的 cs50 课程,这是在黑客版中,所以我不必这样做。这就像额外的家庭作业!
示例:当我在 crypt 函数中加密单词“crimson”时,它变为 50yoN9fp966dU 但是当我从文件中导入它然后加密它时,它是另一回事(50fy ...)。
抱歉,问题很长:|!
如果您愿意,请查看:http: //d2o9nyf4hwsci4.cloudfront.net/2014/x/psets/2/hacker2/hacker2.html#_passwords_em_et_cetera_em
#include <stdio.h>
#include <unistd.h>
#include <cs50.h>
#include <string.h>
#define _XOPEN_SOURCE
char *crypt(const char *key, const char *salt);
int main(int argc, char *argv[])
{
static string cryptedText[500000];
static char word[500000][50];
string salt;
int i = 0;
if (argc != 2)
return 1;
FILE *fp;
fp=fopen("wordsTest.txt","r");
if(fp==NULL)
{
printf("Unable to open file.\n");
exit(1);
}
// the first 2 characters are the salt.
salt = strcat(&argv[1][0], &argv[1][1]);
/*crypt every word in wordsTest with the same "salt" and
test if it equals argv[1](crypted pass) */
do
{
if(fgets(word[i],50,fp)!=NULL)
printf("%i ----> %s",i , word[i]);
cryptedText[i] = crypt(word[i], salt);
printf("%s\n", cryptedText[i]);
i++;
}
while (strcmp(cryptedText[i - 1], argv[1]) != 0);
printf ("%s\n", word[i - 1]);
}
我认为 cryptedText 变量不需要是 500000 (我可以每次都覆盖它)