Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #define _XOPEN_SOURCE
  2.  
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <cs50.h>
  7. #include <stdlib.h>
  8. #include <ctype.h>
  9.  
  10. char salt[2];
  11. char pass[6];
  12. char alpha[] = {'\0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
  13. 't', 'u', 'v', 'w', 'x', 'v', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
  14. 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'W', 'Z'};
  15.  
  16. int main(int argc, string argv[])
  17. {
  18. //chechs if the argument count is 2, if not, prints how to use the program
  19. if (argc != 2)
  20. {
  21. printf("Usage: ./crack hash\n");
  22. return 1;
  23. }
  24. //calculates the salt that is needed for the crypt function
  25. for (int x = 0; x < 2; x++)
  26. {
  27. salt[x] = argv[1][x];
  28. }
  29. /*checks all possible passwords that starts with that symbol, once the password is found and correct,
  30. prints the password and ends the program as completed*/
  31. for (int i = 1, n = 53; i < n; i++)
  32. {
  33. pass[0] = alpha[i];
  34. for (int j = 0; j < n; j++)
  35. {
  36. pass[1] = alpha[j];
  37. for (int k = 0; k < n; k++)
  38. {
  39. pass[2] = alpha[k];
  40. for (int l = 0; l < n; l++)
  41. {
  42. pass[3] = alpha[l];
  43. for (int m = 0; m < n; m++)
  44. {
  45. pass[4] = alpha[m];
  46. //checks if the hashed password with that combination of symbols is the same as the given hash, if yes, prints the password and exits the program
  47. if (strcmp(crypt(pass, salt), argv[1]) == 0)
  48. {
  49. printf("%s\n", pass);
  50. return 0;
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement