title: Tackling a cryptography issue, code takes ages to run, need to optimise it
body: <p>I am building a program where one will use the linux command line to issue a password's hash as the 2nd argument (./program ,to run the program, as the 1st), and the program will find the string with the according hash (aka password) for him. The key needs to be up to 4 characters long (a-z, A-Z), with a 2-digit salt (a-z, A-Z, 0-9). As a total beginner, I cannot come up with something other than using 6 loops to calculate all the possible combinations, which is bound to take the program hours to solve. This problem is part of an online course's problem set (Harvard's cs50), and I am using the course's library, so if you want to be able to use the functions and data types in the program below, so as not to be forced to come up with the corresponding functions/types of the libraries you use, you can create an account on edx and enter cs50.io. Here's the problem's description, if you need any more info: <a href="http://docs.cs50.net/problems/crack/crack.html" rel="nofollow noreferrer">http://docs.cs50.net/problems/crack/crack.html</a></p>
  
  <p>The source code:</p>
  
  <pre><code>#define _XOPEN_SOURCE
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;cs50.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main (int argc, string argv [])
  {
      if (argc != 2){
          printf ("Oops! Goodbye!\n");
          return 1;
      }
  
      char letters [] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',     'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
                          'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E',    'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
                      'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
      char leet [] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
                      'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
                      'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
      char key [4];
      char salt [2];
      int i, j, k, l, m, n;
      for (i = 0; i &lt; 52; i++){
          for (j = 0; j &lt; 52; j++){
              for (k = 0; k &lt; 52; k++){
                  for (l = 0; l &lt; 52; l++){
                      for (m=0; m &lt; 62; m++){
                          for (n=0; n &lt; 62; n++){
                          key [0] = letters [i];
                          key [1] = letters [j];
                          key [2] = letters [k];
                          key [3] = letters [l];
                          salt [0] = leet [m];
                          salt [1] = leet [n];
                          if (strcmp(crypt (key, salt), argv [1])==0){
                              printf ("%c%c%c%c", key [0], key [1], key [2], key [3]);
                              break;
                         }   
                     }   
  
                  }
  
              }
          }
      }
  }
  printf ("\n");
  return 0;
  }
  </code></pre>
  
  <p>Other than the complexity, if you find anything else that can be improved or should be changed, please do tell me. All advice will be highly appreciated.</p>
  
  <p>Edit: Thank you for the time you took into answering. I have taken all your suggestions into account and changed the code, but it still won't run for some reason (it won't print anything, as if the condition (strcmp function) is never satisfied). Could you elaborate as to what could be the problem? One more question. How can I use the debugger in a program that takes command line arguments? Whenever I run the program with the debugger it appears that it takes by default just the "./program" argument and exits. Here's how the new code looks like:</p>
  
  <pre><code>#define _XOPEN_SOURCE
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;cs50.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main (int argc, string argv [])
  {
      char salt [] = "50";
      if (argc != 2)
      {
          printf ("Oops! Goodbye!\n");
          return 1;
      }
  
      char letters [] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
      char key [4];
      int i, j, k, l;
      for (i = 0; i &lt; 52; i++){
          for (j = 0; j &lt; 53; j++){
              for (k = 0; k &lt; 53; k++){
                  for (l = 0; l &lt; 53; l++){
                          key [0] = letters [i];
                          key [1] = letters [j];
                          key [2] = letters [k];
                          key [3] = letters [l];
                          if (strcmp(crypt (key, salt), argv [1])==0)
                          {
                              printf ("%c%c%c%c", key [0], key [1], key [2], key [3]);    
                              break;
                          }
  
                  }
              }
          }
      }
      printf ("\n");
      return 0;
  }
  </code></pre>