Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <crypt.h>
- #include <string.h>
- #define _XOPEN_SOURCE
- #define MAX_LEN 5
- #define SALT_LEN 2
- int main(int argc, string argv[])
- {
- if (argc != 2)
- {
- printf("USAGE: ./crack HASH\n");
- return 1;
- }
- //hello gets hashed to abl0JrMf6tlhw (salt = ab)
- //get hash from cmd line arg
- string hash = argv[1];
- //copy first 2 char's from hash and save as salt (eg: ab)
- char salt[SALT_LEN + 1];
- strncpy(salt, hash, SALT_LEN);
- char guess[MAX_LEN];
- guess[0] = '\0';
- guess[1] = '\0';
- guess[2] = '\0';
- guess[3] = '\0';
- guess[4] = '\0';
- int col = 0;
- while (col < MAX_LEN)
- {
- if (guess[col] == '\0')
- {
- guess[col] = 'a';
- }
- else if (guess[col] == 'z')
- {
- guess[col] = 'A';
- }
- else if (guess[col] == 'Z')
- {
- guess[col] = 'a';
- col++;
- continue;
- }
- else
- {
- guess[col]++;
- }
- string guessHash = crypt(guess,salt);
- if (strcmp(guessHash, hash) == 0)
- {
- printf("Password is %s\n", guess);
- return 0;
- }
- //printf("%s\n", guess);
- col = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement