Guest User

Untitled

a guest
Jan 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. // PROGRAM TO CRACK PASSWORD MADE FROM C's DES bases crypt function
  2.  
  3. //importing libraries
  4. #define _XOPEN_SOURCE
  5. #include <unistd.h>
  6. #include <stdio.h>
  7. #include <cs50.h>
  8. #include <ctype.h>
  9. #include <string.h>
  10.  
  11.  
  12. int main(int argc, string argv[])
  13. {
  14. if (argc != 2) //to check if only two arguments are given
  15. {
  16. printf("Give only two arguments, the filename and hashed password.\n");
  17. return 1;
  18. }
  19.  
  20. char key[] = {argv[1][0], argv[1][1]}; //to etract key from hashed password
  21.  
  22. char pass[6]; //making a temporary array to hold 5 characters
  23. string testpass; //string to hold testing password
  24.  
  25. while (true)
  26. {
  27. for (pass[0] = 'A'; pass[0] <= 'z'; pass[0]++) //condition to crack one lettered password
  28. {
  29. if (isalpha(pass[0]))
  30. {
  31. pass[1] = '\0';
  32. testpass = pass;
  33. if (strcmp(crypt(testpass, key), argv[1]) == 0)
  34. {
  35. printf("%s\n", testpass);
  36. return 0;
  37. break;
  38. }
  39. }
  40. }
  41.  
  42. for (pass[0] = 'A'; pass[0] <= 'z'; pass[0]++) //condition to crack two lettered password
  43. {
  44. if(isalpha(pass[0]))
  45. {
  46. for (pass[1] = 'A'; pass[1] <= 'z'; pass[1]++)
  47. {
  48. if (isalpha(pass[1]))
  49. {
  50. pass[2] = '\0';
  51. testpass = pass;
  52. if (strcmp(crypt(testpass, key), argv[1]) == 0)
  53. {
  54. printf("%s\n", testpass);
  55. return 0;
  56. break;
  57. }
  58. }
  59. }
  60. }
  61. }
  62.  
  63. for (pass[0] = 'A'; pass[0] <= 'z'; pass[0]++) //condition to crack three lettered password
  64. {
  65. if (isalpha(pass[0]))
  66. {
  67. for (pass[1] = 'A'; pass[1] <= 'z'; pass[1]++)
  68. {
  69. if (isalpha(pass[1]))
  70. {
  71. for (pass[2] = 'A'; pass[2] <= 'z'; pass[2]++)
  72. {
  73. if (isalpha(pass[2]))
  74. {
  75. pass[3] = '\0';
  76. testpass = pass;
  77. if (strcmp(crypt(testpass, key), argv[1]) == 0)
  78. {
  79. printf("%s\n", testpass);
  80. return 0;
  81. break;
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89.  
  90. for (pass[0] = 'A'; pass[0] <= 'z'; pass[0]++) //condition to crack four lettered password
  91. {
  92. if (isalpha(pass[0]))
  93. {
  94. for (pass[1] = 'A'; pass[1] <= 'z'; pass[1]++)
  95. {
  96. if (isalpha(pass[1]))
  97. {
  98. for (pass[2] = 'A'; pass[2] <= 'z'; pass[2]++)
  99. {
  100. if (isalpha(pass[2]))
  101. {
  102. for (pass[3] = 'A'; pass[3] <= 'z'; pass[3]++)
  103. {
  104. if (isalpha(pass[3]))
  105. {
  106. pass[4] = '\0';
  107. testpass = pass;
  108. if (strcmp(crypt(testpass, key), argv[1]) == 0)
  109. {
  110. printf("%s\n", testpass);
  111. return 0;
  112. break;
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122.  
  123. for (pass[0] = 'A'; pass[0] <= 'z'; pass[0]++) //condition to crack five lettered password
  124. {
  125. if (isalpha(pass[0]))
  126. {
  127. for (pass[1] = 'A'; pass[1] <= 'z'; pass[1]++)
  128. {
  129. if (isalpha(pass[1]))
  130. {
  131. for (pass[2] = 'A'; pass[2] <= 'z'; pass[2]++)
  132. {
  133. if (isalpha(pass[2]))
  134. {
  135. for (pass[3] = 'A'; pass[3] <= 'z'; pass[3]++)
  136. {
  137. if (isalpha(pass[3]))
  138. {
  139. for (pass[4] = 'A'; pass[4] <= 'z'; pass[4]++)
  140. {
  141. if (isalpha(pass[4]))
  142. {
  143. pass[5] = '\0';
  144. testpass = pass;
  145. if (strcmp(crypt(testpass, key), argv[1]) == 0)
  146. {
  147. printf("%s\n", testpass);
  148. return 0;
  149. break;
  150. }
  151. }
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
Add Comment
Please, Sign In to add comment