Advertisement
ssoni

crack.c

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