Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- #include <crypt.h>
- #include <string.h>
- /*
- brian:51.xJagtPnb6s
- bjbrown:50GApilQSG3E2
- emc:502sDZxA/ybHs
- greg:50C6B0oz0HWzo
- jana:50WUNAFdX/yjA
- lloyd:50n0AAUD.pL8g
- malan:50CcfIk1QrPr6
- natmelo:50JIIyhDORqMU
- rob:51v3Nh6ZWGHOQ
- veronica:61v1CDwwP95bY
- walker:508ny6Rw0aRio
- zamyla:50cI2vYkF0YU2
- */
- bool checkpass(string inputhashes, string generatedpass, string isalt);
- int main(int argc, string argv[])
- {
- if (argc != 2) //checking if the amount of arguments is correct
- {
- printf("Usage: ./crack hash\n");
- return 1;
- }
- string hashedpass = argv[1]; //getting the hashed pass from the argument
- int saltdigits = 2; //
- char salt[saltdigits + 1]; //adding 1 space for the end of the array
- for (int i = 0; i < saltdigits; i++) //taking the salt from the hashedpass
- {
- salt[i] = hashedpass[i];
- }
- string alphabeth = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- int alphalen = strlen(alphabeth);
- //printf("%s\n", crypt("g","20"));
- //checking pass of 1 letter
- for (int i = 0; i < alphalen; i++)
- {
- char key[2];
- key[0] = alphabeth[i];
- if (checkpass(hashedpass, key, salt) == true)
- {
- printf("The password is: %s\n", key);
- return 0;
- }
- }
- //checking pass of 2 letters
- for (int i = 0; i < alphalen; i++) // first letter
- {
- for (int i1 = 0; i1 < alphalen; i1++) // second letter
- {
- char key[3];
- key[0] = alphabeth[i];
- key[1] = alphabeth[i1]; // both letters together
- if (checkpass(hashedpass, key, salt) == true)
- {
- printf("The password is: %s\n", key);
- return 0;
- }
- }
- }
- //checking pass of 3 letters
- for (int i = 0; i < alphalen; i++)
- {
- for (int i1 = 0; i1 < alphalen; i1++)
- {
- for (int i2 = 0; i2 < alphalen; i2++)
- {
- char key[4];
- key[0] = alphabeth[i];
- key[1] = alphabeth[i1];
- key[2] = alphabeth[i2];
- if (checkpass(hashedpass, key, salt) == true)
- {
- printf("The password is: %s\n", key);
- return 0;
- }
- }
- }
- }
- //checking pass of 4 letters
- for (int i = 0; i < alphalen; i++)
- {
- for (int i1 = 0; i1 < alphalen; i1++)
- {
- for (int i2 = 0; i2 < alphalen; i2++)
- {
- for (int i3 = 0; i3 < alphalen; i3++)
- {
- char key[5];
- key[0] = alphabeth[i];
- key[1] = alphabeth[i1];
- key[2] = alphabeth[i2];
- key[3] = alphabeth[i3];
- if (checkpass(hashedpass, key, salt) == true)
- {
- printf("The password is: %s\n", key);
- return 0;
- }
- }
- }
- }
- }
- //checking pass of 5 letters
- for (int i = 0; i < alphalen; i++)
- {
- for (int i1 = 0; i1 < alphalen; i1++)
- {
- for (int i2 = 0; i2 < alphalen; i2++)
- {
- for (int i3 = 0; i3 < alphalen; i3++)
- {
- for (int i4 = 0; i4 < alphalen; i4++)
- {
- char key[6];
- key[0] = alphabeth[i];
- key[1] = alphabeth[i1];
- key[2] = alphabeth[i2];
- key[3] = alphabeth[i3];
- key[4] = alphabeth[i4];
- if (checkpass(hashedpass, key, salt) == true)
- {
- printf("%s\n", key);
- return 0;
- }
- }
- }
- }
- }
- }
- printf("The password wasn't found.\n");
- return 1;
- }
- bool checkpass(string inputhashes, string generatedpass, string isalt) //check if the hashes are equal
- {
- bool result = false;
- string join = crypt(generatedpass, isalt);
- if (strcmp(join, inputhashes) == 0)
- {
- result = true;
- }
- return result;
- }
- // I need to find a way of not repeat all loops
Add Comment
Please, Sign In to add comment