bocajbee

Crack6.c

Jan 13th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6. #include <crypt.h>
  7.  
  8. // easy password for testing:
  9.  
  10. // aaaaa:50XcgR31jl/4M
  11.  
  12. // from problem set docs:
  13.  
  14. // anushree:50xcIMJ0y.RXo = YES
  15. // brian:50mjprEcqC/ts = CA
  16. // bjbrown:50GApilQSG3E2 = UPenn (takes a while)
  17. // lloyd:50n0AAUD.pL8g = lloyd (takes a while)
  18. // malan:50CcfIk1QrPr6 = maybe (takes a while)
  19. // maria:509nVI8B9VfuA = TF
  20. // natmelo:50JIIyhDORqMU = nope
  21. // rob:50JGnXUgaafgc = ROFL
  22. // stelios:51u8F0dkeDSbY = NO
  23. // zamyla:50cI2vYkF0YU2 = LOL
  24.  
  25. bool crack(char *user_input, char *guess, char *salt);
  26.  
  27. int main(int argc, string *argv[])
  28. {
  29.     if (argc != 2)  // prevent the user from not entering the correct number of command line arguments
  30.     {
  31.         printf("Invalid Hash Needed!:\n ");
  32.         return 1;
  33.     }
  34.  
  35.     string *user_input = argv[1]; // declare a pointer called user input (which we have also stated is argv[1])
  36.     char salt[3];
  37.  
  38.     for (int i = 0; i < 2; i++)
  39.     {
  40.         salt[i] = *user_input[i];
  41.         salt[2] = '\0';
  42.     }
  43.  
  44.     string alphabet = "ABC";
  45.     char guess[1];
  46.  
  47.     for (int a1 = 0; a1 < strlen(alphabet); a1++)  // check onenote for how these forloops work
  48.     {
  49.         guess[0] = alphabet[a1];
  50.         guess[1] = '\0';
  51.         // The crypt function takes a password, key, as a string, and a salt character array which is described below, and returns a printable ASCII string which starts with another salt. It is believed
  52.         // that, given the output of the function, the best way to find a key that will produce that output is to guess values of key until the original value of key is found.
  53.         if (crack(alphabet, guess, salt))
  54.       {
  55.         printf("Password is: %s\n", guess);
  56.         return 0;
  57.       }
  58.     }
  59.     printf("\n");
  60. }
  61.  
  62. // derefrencing the pointers for user input, guess[i]th index & salt at [i]th index in our crack function so we can update these pointers declared in main within this function
  63. // without having to fuck around with making copies of this data and passing it back etc
  64. bool crack(char *user_input, char *guess, char *salt)
  65. {
  66.     char *encrypted_guess = crypt(guess, salt);
  67.  
  68.     if (strcmp(encrypted_guess, user_input) == 0)
  69.     {
  70.         return true;
  71.     }
  72.     else
  73.     {
  74.         return false;
  75.     }
  76. }
Add Comment
Please, Sign In to add comment