Advertisement
Guest User

Beter code

a guest
Oct 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.17 KB | None | 0 0
  1. #define _XOPEN_SOURCE
  2. #include <unistd.h>
  3. #include<cs50.h>
  4. #include<stdio.h>
  5. #include<string.h>
  6. //To include usage of functions isupper and islower
  7. #include <ctype.h>
  8.  
  9. int main(int argc, string argv[])
  10. {
  11.  
  12.     //Check whether there is only a single command-line argument passed when running ./crack
  13.     if (argc != 2)
  14.     {
  15.         printf("The program only accepts a single command-line argument. Please re-run the program and insert a word as an argument\n");
  16.         return 1;
  17.     }
  18.     string hash = argv[1];
  19.     string encryptedHash;
  20.     char arrChars[3] = {hash[0], hash[1], '\0'};
  21.     string salt = arrChars;
  22.     char password[5];
  23.     password[4] = '\0';
  24.     for (int i = 0; i < 51; i++)
  25.     {
  26.         for (int j = 0; j < 51; j++)
  27.         {
  28.             for (int k = 0; k < 51; k++)
  29.             {
  30.                 for (int l = 0; l < 51; l++)
  31.                 {
  32.                     for (int m = 0; m < 51; m++)
  33.                     {
  34.                         //For loop Begins
  35.                         if (strcmp(password, "") == 0)
  36.                         {
  37.                             password[0] = 'a';
  38.                             password[0] += 1;
  39.                         }
  40.                         else
  41.                         {
  42.                             if (m > 24)
  43.                             {
  44.                                 if (m == 25)
  45.                                 {
  46.                                     password[0] = 'A';
  47.                                 }
  48.                                 else
  49.                                 {
  50.                                     if (password[0] == 'Z')
  51.                                     {
  52.                                         password[0] = 'a';
  53.                                     }
  54.                                     else
  55.                                     {
  56.                                         password[0]++;
  57.                                     }
  58.  
  59.                                 }
  60.                             }
  61.                             //Split Uppercase Letters(^) and Lowercase Letters(v)
  62.                             else
  63.                             {
  64.                                 password[0]++;
  65.                             }
  66.                         }
  67.                         if (strcmp(crypt(password, salt), hash) == 0)
  68.                         {
  69.                             printf("Password found: %s", password);
  70.                             return 1;
  71.                         }
  72.                         printf("%s\n",password);
  73.                     }
  74.                     //For loop Begins
  75.                     if (strcmp(&password[1], "") == 0)
  76.                     {
  77.                         password[1] = 'a';
  78.                         password[1] += 1;
  79.                     }
  80.                     else
  81.                     {
  82.                         if (l > 24)
  83.                         {
  84.                             if (l == 25)
  85.                             {
  86.                                 password[1] = 'A';
  87.                             }
  88.                             else
  89.                             {
  90.                                 if (password[1] == 'Z')
  91.                                 {
  92.                                     password[1] = 'a';
  93.                                 }
  94.                                 else
  95.                                 {
  96.                                     password[1]++;
  97.                                 }
  98.  
  99.                             }
  100.                         }
  101.                         //Split Uppercase Letters(^) and Lowercase Letters(v)
  102.                         else
  103.                         {
  104.                             password[1]++;
  105.                         }
  106.                     }
  107.                     if (strcmp(crypt(password, salt), hash) == 0)
  108.                     {
  109.                         printf("Password found: %s", password);
  110.                         return 1;
  111.                     }
  112.                     printf("%s\n",password);
  113.                 }
  114.                 //For loop Begins
  115.                 if (strcmp(&password[2], "") == 0)
  116.                 {
  117.                     password[2] = 'a';
  118.                     password[2] += 1;
  119.                 }
  120.                 else
  121.                 {
  122.                     if (k > 24)
  123.                     {
  124.                         if (k == 25)
  125.                         {
  126.                             password[2] = 'A';
  127.                         }
  128.                         else
  129.                         {
  130.                             if (password[2] == 'Z')
  131.                             {
  132.                                 password[2] = 'a';
  133.                             }
  134.                             else
  135.                             {
  136.                                 password[2]++;
  137.                             }
  138.  
  139.                         }
  140.                     }
  141.                     //Split Uppercase Letters(^) and Lowercase Letters(v)
  142.                     else
  143.                     {
  144.                         password[2]++;
  145.                     }
  146.                 }
  147.                 if (strcmp(crypt(password, salt), hash) == 0)
  148.                 {
  149.                     printf("Password found: %s", password);
  150.                     return 1;
  151.                 }
  152.                 printf("%s\n",password);
  153.             }
  154.             //For loop Begins
  155.             if (strcmp(&password[3], "") == 0)
  156.             {
  157.                 password[3] = 'a';
  158.                 password[3] += 1;
  159.             }
  160.             else
  161.             {
  162.                 if (j > 24)
  163.                 {
  164.                     if (j == 25)
  165.                     {
  166.                         password[3] = 'A';
  167.                     }
  168.                     else
  169.                     {
  170.                         if (password[3] == 'Z')
  171.                         {
  172.                             password[3] = 'a';
  173.                         }
  174.                         else
  175.                         {
  176.                             password[3]++;
  177.                         }
  178.  
  179.                     }
  180.                 }
  181.                 //Split Uppercase Letters(^) and Lowercase Letters(v)
  182.                 else
  183.                 {
  184.                     password[3]++;
  185.                 }
  186.             }
  187.             if (strcmp(crypt(password, salt), hash) == 0)
  188.             {
  189.                 printf("Password found: %s", password);
  190.                 return 1;
  191.             }
  192.             printf("%s\n",password);
  193.         }
  194.         //For loop Begins
  195.         if (strcmp(&password[4], "") == 0)
  196.         {
  197.             password[4] = 'a';
  198.             password[4] += 1;
  199.         }
  200.         else
  201.         {
  202.             if (i > 24)
  203.             {
  204.                 if (i == 25)
  205.                 {
  206.                     password[4] = 'A';
  207.                 }
  208.                 else
  209.                 {
  210.                     if (password[4] == 'Z')
  211.                     {
  212.                         password[4] = 'a';
  213.                     }
  214.                     else
  215.                     {
  216.                         password[4]++;
  217.                     }
  218.  
  219.                 }
  220.             }
  221.             //Split Uppercase Letters(^) and Lowercase Letters(v)
  222.             else
  223.             {
  224.                 password[4]++;
  225.             }
  226.         }
  227.         if (strcmp(crypt(password, salt), hash) == 0)
  228.         {
  229.             printf("Password found: %s", password);
  230.             return 1;
  231.         }
  232.     }
  233.     return 0;
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement