SHARE
TWEET

Untitled

a guest Jun 25th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <crypt.h>
  5.  
  6. char next(char c);
  7.  
  8. int main(int argc, string argv[])
  9. {
  10.     //check correct usage.
  11.     if (argc == 2)
  12.     {}
  13.     else
  14.     {
  15.         printf("Usage ./crack hash\n");
  16.         return 1;
  17.     }
  18.     //initialize starting variables
  19.     string key = argv[1];
  20.     bool result = false;
  21.     char word[6] = "\0";
  22.     word[0] = 'A';
  23.  
  24.     //extract salt
  25.     char salt[3];
  26.     salt[0] = key[0];
  27.     salt[1] = key[1];
  28.     salt[2] = '\0';
  29.  
  30.     // main loop
  31.     while(!result)
  32.     {
  33.        
  34.         //check if word yield correct hash
  35.         if (strcmp(crypt(word, salt), argv[1]) == 0)
  36.         {
  37.             result = true;
  38.             break;
  39.         }
  40.         // for each character in word
  41.         for (int n = strlen(word)-1; n >= 0; n--)
  42.         {
  43.             //check if word is final option available ('z')
  44.             if (word[n] == 'z')
  45.             {
  46.                 // if first letter is final option available assume every other letter in word is also final option
  47.                 // increment each one and add another letter
  48.                 if (n == 0)
  49.                 {
  50.                     int k = strlen(word);
  51.                     for (int j = 0;  j < k ;j++)
  52.                     {
  53.                         word[j+1] = 'A';
  54.                     }
  55.                 }
  56.                 word[n] = next(word[n]);
  57.             }
  58.             // if letter is not final option, change letter to next letter available
  59.             else
  60.             {
  61.                 word[n] = next(word[n]);
  62.                 break;
  63.             }
  64.         }
  65.     }
  66.     // if correct result is found print it
  67.     printf("result is: %s\n",word);
  68. }
  69.  
  70. //function for easy changing of available option pool.
  71. char next(char c)
  72. {
  73.     c = c + 1;
  74.     if (c == 'Z' + 1)
  75.     {
  76.         c = 'a';
  77.     }
  78.     if (c == 'z' + 1)
  79.     {
  80.         c = 'A';
  81.     }
  82.     return c;
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top