Created
February 14, 2017 01:41
-
-
Save miquilenadiego/df87331d3c7d0ba2c19af7dcd12ef13e to your computer and use it in GitHub Desktop.
crack.c
This file contains 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 <unistd.h> | |
#include <cs50.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <ctype.h> | |
int toasci(int c); | |
int main(int argc, string argv[]) | |
{ | |
if (argc != 2) | |
{ | |
printf("Usage: ./crack hash\n"); | |
return 1; | |
} | |
char passwd[5]; | |
string cracked; | |
int i; | |
for (i = 0; i < 4; i++) | |
{ | |
if (i == 0) | |
{ | |
int j = 0; | |
do | |
{ | |
passwd[0] = toasci(j); | |
passwd[1] = '\0'; | |
cracked = crypt(passwd,"50"); | |
j++; | |
if(strcmp(cracked,argv[1]) == 0) | |
{ | |
printf("%s\n", passwd); | |
return 1; | |
} | |
} while (j < 52); | |
} | |
else if (i == 1) | |
{ | |
int j = 0; | |
do | |
{ | |
passwd[0] = toasci(j); | |
int k = 0; | |
do{ | |
passwd[1] = toasci(k); | |
passwd[2] = '\0'; | |
cracked = crypt(passwd,"50"); | |
k++; | |
if(strcmp(cracked,argv[1]) == 0) | |
{ | |
printf("%s\n", passwd); | |
return 1; | |
} | |
}while (k < 52); | |
j++; | |
} while (j < 52); | |
} | |
else if (i == 2) | |
{ | |
int j = 0; | |
do | |
{ | |
passwd[0] = toasci(j); | |
int k = 0; | |
do{ | |
passwd[1] = toasci(k); | |
int l = 0; | |
do | |
{ | |
passwd[2] = toasci(l); | |
passwd[3] = '\0'; | |
cracked = crypt(passwd,"50"); | |
l++; | |
if(strcmp(cracked,argv[1]) == 0) | |
{ | |
printf("%s\n", passwd); | |
return 1; | |
} | |
} while (l < 52); | |
k++; | |
}while (k < 52); | |
j++; | |
} while (j < 52); | |
} | |
else if (i == 3) | |
{ | |
int j = 0; | |
do | |
{ | |
passwd[0] = toasci(j); | |
int k = 0; | |
do{ | |
passwd[1] = toasci(k); | |
int l = 0; | |
do | |
{ | |
passwd[2] = toasci(l); | |
int m = 0; | |
do | |
{ | |
passwd[3] = toasci(m); | |
passwd[4] = '\0'; | |
cracked = crypt(passwd,"50"); | |
m++; | |
if(strcmp(cracked,argv[1]) == 0) | |
{ | |
printf("%s\n", passwd); | |
return 1; | |
} | |
}while (m < 52); | |
l++; | |
} while (l < 52); | |
k++; | |
}while (k < 52); | |
j++; | |
} while (j < 52); | |
} | |
} | |
printf("%s\n", passwd); | |
} | |
int toasci(int c) | |
{ | |
int ascii; | |
if (c >= 0 && c <= 25) | |
{ | |
ascii = 65; | |
int upper = 0; | |
while (upper < c) | |
{ | |
ascii++; | |
upper++; | |
} | |
} | |
else | |
{ | |
ascii = 97; | |
int lower = 26; | |
while (lower < c) | |
{ | |
ascii++; | |
lower++; | |
} | |
} | |
return ascii; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment