Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _XOPEN_SOURCE
- #define DOUBLE_ALPHA 52
- #include <cs50.h>
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- int main(int argc, string argv[])
- {
- // prompt user for hash password from the cmd line, limited to 1 argument only
- if (argc != 2)
- {
- printf("Usage: ./crack hash\n");
- return 1;
- }
- // get "salt" for crypt() by retrieving the first two characters of argv[1]
- char salt[3];
- salt[0] = argv[1][0];
- salt[1] = argv[1][1];
- // password may have up to four characters in length
- char password[5];
- string alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- // testing for password with one character length
- for (int i = 0; i < DOUBLE_ALPHA; i++)
- {
- password[1] = '\0';
- password[0] = alphabets[i];
- string hash2 = crypt(password, salt);
- if (strcmp(argv[1], hash2))
- {
- printf("Password: %s\n", password);
- return 0;
- }
- }
- // testing for password with two characters length
- for (int i = 0; i < DOUBLE_ALPHA; i++)
- {
- password[2] = '\0';
- password[0] = alphabets[i];
- for (int j = 0; j < DOUBLE_ALPHA; j++)
- {
- password[1] = alphabets[j];
- string hash2 = crypt(password, salt);
- if (strcmp(argv[1], hash2))
- {
- printf("Password: %s\n", password);
- return 0;
- }
- }
- }
- // testing for password with three characters length
- for (int i = 0; i < DOUBLE_ALPHA; i++)
- {
- password[3] = '\0';
- password[0] = alphabets[i];
- for (int j = 0; j < DOUBLE_ALPHA; j++)
- {
- password[1] = alphabets[j];
- for (int k = 0; k < DOUBLE_ALPHA; k++)
- {
- password[2] = alphabets[k];
- string hash2 = crypt(password, salt);
- if (strcmp(argv[1], hash2))
- {
- printf("Password: %s\n", password);
- return 0;
- }
- }
- }
- }
- // testing for password with four characters length
- for (int i = 0; i < DOUBLE_ALPHA; i++)
- {
- password[4] = '\0';
- password[0] = alphabets[i];
- for (int j = 0; j < DOUBLE_ALPHA; j++)
- {
- password[1] = alphabets[j];
- for (int k = 0; k < DOUBLE_ALPHA; k++)
- {
- password[2] = alphabets[k];
- for (int l = 0; l < DOUBLE_ALPHA; l++)
- {
- password[3] = alphabets[l];
- string hash2 = crypt(password, salt);
- if (strcmp(argv[1], hash2))
- {
- printf("Password: %s\n", password);
- return 0;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement