Normantas

Cs50 2018 Crack Solution

Dec 28th, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.84 KB | None | 0 0
  1. #define _XOPEN_SOURCE /*note, this software is 99% completed or should work, but it doesn't, cause when I unput my key and the salt into an if statement to test the key, it outputs me a different hash. */
  2. #include <stdio.h>
  3. #include <cs50.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <crypt.h>
  7. #include <unistd.h>
  8.  
  9. void crackPassword(string hash);
  10.  
  11. int main(int argc, string argv[])
  12. {
  13.     if(argc == 2)
  14.     {
  15.         crackPassword(argv[1]);
  16.     }
  17.     else
  18.     {
  19.     printf("Error. \n");
  20.     }
  21. }
  22.  
  23. void crackPassword(string hash)
  24. {
  25.     char key[6] = "\0\0\0\0\0\0"; //5 Characters starting from A.. // Out Data;
  26.     char salt[2] = "";
  27.     salt[0] = hash[0];
  28.     salt[1] = hash[1];
  29.     int a[5]; a[0] = 0; a[1] = 0; a[2] = 0; a[3] = 0; a[4] = 0; //defines ints assigned to numbers (1-25 : A-Z |||||| 26 - 50 : a - z)
  30.     bool boolLoop = true;
  31.     do
  32.     {
  33.         a[0]++; //loops through every letter possible
  34.         for(int y = 0; y < 4; y++ ) //calculates the change of the letters;
  35.         {
  36.             if (a[y] > 52)
  37.             {
  38.                 a[y + 1]++;
  39.                 a[0] = 1;
  40.             }
  41.         }
  42.         for(int i = 0; i < 5; i++)
  43.         {
  44.             int typeIn;
  45.             if (a[i] < 26 && a[i] > 0)
  46.             {
  47.                 typeIn = 64 + a[i];
  48.                 key[i] = (char)typeIn;
  49.             }
  50.             else if(a[i] > 25)
  51.             {
  52.                 typeIn = 96 + a[i] - 25;
  53.                 key[i] = (char)typeIn;
  54.             }
  55.         }
  56.         if(strcmp(crypt(key, salt), hash) == 0)
  57.         {
  58.             boolLoop = false;
  59.         }
  60.         if (a[4] > 50){
  61.         printf("hash is fake");
  62.         boolLoop = false;
  63.         }
  64.     }
  65.     while(boolLoop == true); //a[4] > 50 -statement means, that the program has checked all the possible passwords.
  66.     printf("%s \n",key);
  67. }
Add Comment
Please, Sign In to add comment