I'm making a program in C to crack DES-based encrypted password, It takes the password as an argument and gives me the password.
What I did was trying 500000 words by encrypting them in the same salt (first 2 letters) and then compare it with argv[1] (which is the encrypted password that I want to crack). I think it's called brute force (trying everything possible). anyway my problem is when I encrypt the words I get different encryption (same salt and same key) as you see I print the number, words and the encryption (just to check if it works) you can remove them if you want!
btw I got the code that reads the line from file from some website, since I'm new to C and I haven't learnt about files yet!
Please be gentle I'm really new here :D, and if you got a comment of the design or code just tell me :)!
BTW I'm taking cs50 course from XHarved, and this is in the hacker edition, so I don't have to do it. It's like extra homework!
Example: when I crypt the word "crimson" in the crypt function it becomes 50yoN9fp966dU but when I import it from a file and then crypt it, it's something else (50fy...).
Sorry for the long question :|!
See it if you want: 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]);
}
I think the cryptedText variable doesn't need to be 500000 (I can overwritte it everytime)