Created
July 29, 2019 14:28
-
-
Save Hamleyburger/59754b89c40284437b28a1287c065c62 to your computer and use it in GitHub Desktop.
My attempt at crack, cs50
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
#include <cs50.h> | |
#include <stdio.h> | |
#include <crypt.h> | |
#include <string.h> | |
#include <math.h> | |
void allpossible1(string hash, string salt); | |
void allpossible2(string hash, string salt); | |
void allpossible3(string hash, string salt); | |
void allpossible4(string hash, string salt); | |
void allpossible5(string hash, string salt); | |
bool checkarg(int argc); | |
bool comparekey(string chars, string hash, string salt); | |
int main(int argc, string argv[]) | |
{ | |
if (!checkarg(argc)) | |
{ | |
printf("Usage: ./crack hash\n"); | |
return 1; | |
} | |
// Two strings are given as arguments | |
printf("to test for word %s, copy paste: %s\n", "Aa", crypt("Aa", argv[1])); | |
allpossible1(argv[1], argv[1]); | |
allpossible2(argv[1], argv[1]); | |
allpossible3(argv[1], argv[1]); | |
allpossible4(argv[1], argv[1]); | |
allpossible5(argv[1], argv[1]); | |
} | |
bool comparekey(string chars, string hash, string salt) | |
{ | |
if (strcmp(crypt(chars, salt), hash) == 0) | |
{ | |
printf("%s\n", chars); | |
exit(0); | |
return true; | |
} | |
return false; | |
} | |
bool checkarg(int argc) | |
{ | |
if (argc != 2) | |
{ | |
return false; | |
} | |
else | |
{ | |
return true; | |
} | |
} | |
void allpossible1(string hash, string salt) | |
{ | |
int places = 1; | |
char chars[places]; | |
char letters[] = {'e', 'E', 't', 'T', 'a', 'A', 'o', 'O', 'i', 'I', 'n', 'N', 's', 'S', 'r', 'R', 'h', 'H', 'l', 'L', 'd', 'D', 'c', 'C', 'u', 'U', 'm', 'M', 'f', 'F', 'p', 'P', 'g', 'G', 'w', 'W', 'y', 'Y', 'b', 'B', 'v', 'V', 'k', 'K', 'x', 'X', 'j', 'J', 'q', 'Q', 'z', 'Z'}; | |
int alphalength = 52; | |
// "Forever" loop. | |
for (int i = 0; i < alphalength; i++) | |
{ | |
// Keep looping first char through alphabet and print each iteration | |
chars[0] = letters[i]; | |
if(comparekey(chars, hash, salt) == true) | |
{ | |
exit(0); | |
} | |
//printf("%s\n", chars); | |
} | |
} | |
void allpossible2(string hash, string salt) | |
{ | |
int places = 2; | |
char chars[places]; | |
char letters[] = {'e', 'E', 't', 'T', 'a', 'A', 'o', 'O', 'i', 'I', 'n', 'N', 's', 'S', 'r', 'R', 'h', 'H', 'l', 'L', 'd', 'D', 'c', 'C', 'u', 'U', 'm', 'M', 'f', 'F', 'p', 'P', 'g', 'G', 'w', 'W', 'y', 'Y', 'b', 'B', 'v', 'V', 'k', 'K', 'x', 'X', 'j', 'J', 'q', 'Q', 'z', 'Z'}; | |
int alphalength = 52; // Der må være en bedre måde at definere længden på letters. | |
// Ved ikke om jeg skal bruge dem | |
int iterations[places]; | |
// Fill interations with 0s for starters | |
for (int y = 0; y < places; y++) | |
{ | |
iterations[y] = 0; | |
} | |
for (int i = 0; i < alphalength; i++) | |
{ | |
// Keep looping first char through alphabet and print each iteration | |
chars[0] = letters[i]; | |
for (int j = 0; j < alphalength; j++) | |
{ | |
chars[1] = letters[j]; | |
if(comparekey(chars, hash, salt) == true) | |
{ | |
exit(0); | |
} | |
//printf("%s\n", chars); | |
} | |
} | |
} | |
void allpossible3(string hash, string salt) | |
{ | |
int places = 3; | |
char chars[places]; | |
char letters[] = {'e', 'E', 't', 'T', 'a', 'A', 'o', 'O', 'i', 'I', 'n', 'N', 's', 'S', 'r', 'R', 'h', 'H', 'l', 'L', 'd', 'D', 'c', 'C', 'u', 'U', 'm', 'M', 'f', 'F', 'p', 'P', 'g', 'G', 'w', 'W', 'y', 'Y', 'b', 'B', 'v', 'V', 'k', 'K', 'x', 'X', 'j', 'J', 'q', 'Q', 'z', 'Z'}; | |
int alphalength = 52; // Der må være en bedre måde at definere længden på letters. | |
// Ved ikke om jeg skal bruge dem | |
int iterations[places]; | |
// Fill interations with 0s for starters | |
for (int y = 0; y < places; y++) | |
{ | |
iterations[y] = 0; | |
} | |
for (int i = 0; i < alphalength; i++) | |
{ | |
// Keep looping first char through alphabet and print each iteration | |
chars[0] = letters[i]; | |
for (int j = 0; j < alphalength; j++) | |
{ | |
chars[1] = letters[j]; | |
for (int k = 0; k < alphalength; k++) | |
{ | |
chars[2] = letters[k]; | |
if(comparekey(chars, hash, salt) == true) | |
{ | |
exit(0); | |
} | |
//printf("%s\n", chars); | |
} | |
} | |
} | |
} | |
void allpossible4(string hash, string salt) | |
{ | |
int places = 4; | |
char chars[places]; | |
char letters[] = {'e', 'E', 't', 'T', 'a', 'A', 'o', 'O', 'i', 'I', 'n', 'N', 's', 'S', 'r', 'R', 'h', 'H', 'l', 'L', 'd', 'D', 'c', 'C', 'u', 'U', 'm', 'M', 'f', 'F', 'p', 'P', 'g', 'G', 'w', 'W', 'y', 'Y', 'b', 'B', 'v', 'V', 'k', 'K', 'x', 'X', 'j', 'J', 'q', 'Q', 'z', 'Z'}; | |
int alphalength = 52; // Der må være en bedre måde at definere længden på letters. | |
// Ved ikke om jeg skal bruge dem | |
int iterations[places]; | |
// Fill interations with 0s for starters | |
for (int y = 0; y < places; y++) | |
{ | |
iterations[y] = 0; | |
} | |
for (int i = 0; i < alphalength; i++) | |
{ | |
// Keep looping first char through alphabet and print each iteration | |
chars[0] = letters[i]; | |
for (int j = 0; j < alphalength; j++) | |
{ | |
chars[1] = letters[j]; | |
for (int k = 0; k < alphalength; k++) | |
{ | |
chars[2] = letters[k]; | |
for (int l = 0; l < alphalength; l++) | |
{ | |
chars[3] = letters[l]; | |
if(comparekey(chars, hash, salt) == true) | |
{ | |
exit(0); | |
} | |
//printf("%s\n", chars); | |
} | |
} | |
} | |
} | |
} | |
void allpossible5(string hash, string salt) | |
{ | |
int places = 5; | |
char chars[places]; | |
char letters[] = {'e', 'E', 't', 'T', 'a', 'A', 'o', 'O', 'i', 'I', 'n', 'N', 's', 'S', 'r', 'R', 'h', 'H', 'l', 'L', 'd', 'D', 'c', 'C', 'u', 'U', 'm', 'M', 'f', 'F', 'p', 'P', 'g', 'G', 'w', 'W', 'y', 'Y', 'b', 'B', 'v', 'V', 'k', 'K', 'x', 'X', 'j', 'J', 'q', 'Q', 'z', 'Z'}; | |
int alphalength = 52; // Der må være en bedre måde at definere længden på letters. | |
// Ved ikke om jeg skal bruge dem | |
int iterations[places]; | |
// Fill interations with 0s for starters | |
for (int y = 0; y < places; y++) | |
{ | |
iterations[y] = 0; | |
} | |
for (int i = 0; i < alphalength; i++) | |
{ | |
// Keep looping first char through alphabet and print each iteration | |
chars[0] = letters[i]; | |
for (int j = 0; j < alphalength; j++) | |
{ | |
chars[1] = letters[j]; | |
for (int k = 0; k < alphalength; k++) | |
{ | |
chars[2] = letters[k]; | |
for (int l = 0; l < alphalength; l++) | |
{ | |
chars[3] = letters[l]; | |
for (int m = 0; m < alphalength; m++) | |
{ | |
chars[4] = letters[m]; | |
if(comparekey(chars, hash, salt) == true) | |
{ | |
exit(0); | |
} | |
//printf("%s\n", chars); | |
} | |
} | |
} | |
} | |
} | |
} |
and
Of course, you will be a great help even if you help me with something small. I also spend all my spare time in programming, I have about two hours a day for programming
but i need any other communication way
and
Of course, you will be a great help even if you help me with something small. I also spend all my spare time in programming, I have about two hours a day for programming
Hey! Sure. Discord id: Alma#0240
ok, i sent you a request on Discord Agree it
and if it didnt come so my
Discord id: HOK4AWII#6770
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK, thanks alot and im same thing im on the last final project :) as i have only one friend who is learning programming
and while im solving problems or learning i find things i cant understand but he is learning some different languages
but i have one problem here :(
i don't open GitHub a lot and maybe i dont know how to use it so if you have any popular communication way that i can communicate with you on it
and thanks ,for a new friend