Created
March 1, 2018 13:00
-
-
Save prateek-parashar/1cb50d2140f76150fb5591d306992530 to your computer and use it in GitHub Desktop.
Code to crack passwords hashed using the DES algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _XOPEN_SOURCE | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <cs50.h> | |
#include <string.h> | |
int main(int argc, string argv[]) | |
{ | |
//taking in the hashed input from the user | |
if (argc != 2) | |
{ | |
printf("Usage ./crack Hashed Password\n"); | |
return 1; | |
} | |
string hash = argv[1]; | |
//initialising salt as 50 | |
string salt = "50"; | |
//testing for one character password | |
char password1[2]; | |
password1[1] = '\0'; | |
for (int i = 'A'; i <= 'z'; i++) | |
{ | |
password1[0] = i; | |
if (strcmp(crypt(password1, salt), hash) == 0) | |
{ | |
printf("%s\n",password1); | |
return 0; | |
} | |
} | |
//testing for two character password | |
char password2[3]; | |
password2[2] = '\0'; | |
for (char i = 'A'; i < 'z'; i++) | |
{ | |
password2[0] = i; | |
for (int j = 'A'; j < 'z'; j++) | |
{ | |
password2[1] = j; | |
if (strcmp(crypt(password2, salt), hash) == 0) | |
{ | |
printf("%s\n",password2); | |
return 0; | |
} | |
} | |
} | |
//testing for three character password | |
char password3[4]; | |
password3[3] = '\0'; | |
for (char i = 'A'; i < 'z'; i++) | |
{ | |
password3[0] = i; | |
for (int j = 'A'; j < 'z'; j++) | |
{ | |
password3[1] = j; | |
for (int k = 'A'; k <= 'z'; k++) | |
{ | |
if (k <= 'Z' && k >= 'a') | |
{ | |
password3[2] = k; | |
if (strcmp(crypt(password2, salt), hash) == 0) | |
{ | |
printf("%s\n",password2); | |
return 0; | |
} | |
} | |
} | |
} | |
} | |
//testing for four character password | |
char password4[5]; | |
password4[4] = '\0'; | |
for (char i = 'A'; i < 'z'; i++) | |
{ | |
password4[0] = i; | |
for (int j = 'A'; j < 'z'; j++) | |
{ | |
password4[1] = j; | |
for (int k = 'A'; k <= 'z'; k++) | |
{ | |
password4[2] = k; | |
for (int l = 'A'; l <= 'z'; l++) | |
{ | |
password4[3] = l; | |
if (strcmp(crypt(password2, salt), hash) == 0) | |
{ | |
printf("%s\n",password2); | |
return 0; | |
} | |
} | |
} | |
} | |
} | |
//testing for five character password | |
char password5[6]; | |
password5[5] = '\0'; | |
for (char i = 'A'; i < 'z'; i++) | |
{ | |
password5[0] = i; | |
for (int j = 'A'; j < 'z'; j++) | |
{ | |
password5[1] = j; | |
for (int k = 'A'; k <= 'z'; k++) | |
{ | |
password5[2] = k; | |
for (int l = 'A'; l <= 'z'; l++) | |
{ | |
password5[3] = l; | |
for (int m = 'A'; m <= 'z'; m++) | |
{ | |
password5[4] = m; | |
if (strcmp(crypt(password5, salt), hash) == 0) | |
{ | |
printf("%s\n",password5); | |
return 0; | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment