Advertisement
ssoni

crack.c

Apr 27th, 2021
953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.32 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <crypt.h>
  4. #include <string.h>
  5.  
  6. #define _XOPEN_SOURCE
  7. #define MAX_LEN 5
  8. #define SALT_LEN 2
  9.  
  10. int main(int argc, string argv[])
  11. {
  12.     if (argc != 2)
  13.     {
  14.         printf("USAGE: ./crack HASH\n");
  15.         return 1;
  16.     }
  17.  
  18.     //hello gets hashed to abl0JrMf6tlhw (salt = ab)
  19.  
  20.     //get hash from cmd line arg
  21.     string hash = argv[1];
  22.  
  23.     //copy first 2 char's from hash and save as salt (eg: ab)
  24.     char salt[SALT_LEN + 1];
  25.     strncpy(salt, hash, SALT_LEN);
  26.  
  27.     char guess[MAX_LEN];
  28.     guess[0] = '\0';
  29.     guess[1] = '\0';
  30.     guess[2] = '\0';
  31.     guess[3] = '\0';
  32.     guess[4] = '\0';
  33.  
  34.     int col = 0;
  35.  
  36.     while (col < MAX_LEN)
  37.     {
  38.         if (guess[col] == '\0')
  39.         {
  40.             guess[col] = 'a';
  41.         }
  42.         else if (guess[col] == 'z')
  43.         {
  44.             guess[col] = 'A';
  45.         }
  46.         else if (guess[col] == 'Z')
  47.         {
  48.             guess[col] = 'a';
  49.             col++;
  50.             continue;
  51.         }
  52.         else
  53.         {
  54.             guess[col]++;
  55.         }
  56.         string guessHash = crypt(guess,salt);
  57.         if (strcmp(guessHash, hash) == 0)
  58.         {
  59.             printf("Password is %s\n", guess);
  60.             return 0;
  61.         }
  62.         //printf("%s\n", guess);
  63.         col = 0;
  64.     }
  65.  
  66.  
  67. }
  68.  
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement