title: CS50 Why can't my code crack a four digit password?
body: <p>I've encountered a problem in C that held me for the past 6 hours, and after research and studies, I decided to seek for help! Sorry, my English is not my first language and I am a beginner coder. </p>
  
  <p>I am able to crack all passwords that are three digits long. However, it seems like I cannot crack passwords that are four digits long. I've tried my best to make some comprehension and figure out my mistakes in the code, but it seems I cannot do so. Please help!</p>
  
  <p>Also, it would be very nice if there would be more explanations why I cannot crack a four digit long passwords instead of plain solution. Thank you in advance!</p>
  
  <pre><code>#define _XOPEN_SOURCE
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;cs50.h&gt;
  #include &lt;crypt.h&gt;
  #include &lt;unistd.h&gt;
  
  int main (int argc, char* argv[])
  {
  
      if (argc != 2){
          printf("Invalid input\n");
          return 1;
      }
  
      char* hash = argv[1];
      char code[4];
      char* alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
      int length = strlen(alphabet);
  
      for (int a = 0; a &lt;= length; a++)
      {
          code[0] = alphabet[a];
          printf("%s\n", code);
          if (strcmp(crypt(code, "50"), hash) == 0)
          {
              printf("%s\n", code);
              return 0;
          }
  
          for (int b = 0; b &lt;= length; b++)
          {
              code[1] = alphabet[b];
              //printf("%s\n", code[1]);
              if (strcmp(crypt(code, "50"), hash) == 0)
              {
                  printf("%s\n", code);
                  return 0;
              }
  
              for (int c = 0; c &lt;= length; c++)
              {
                  code[2] = alphabet[c];
                  //printf("%s\n", code[2]);
                  if (strcmp(crypt(code, "50"), hash) == 0)
                  {
                      printf("%s\n", code);
                      return 0;
                  }
  
                  for (int d = 0; d &lt;= length; d++)
                  {
                      code[3] = alphabet[d];
                      //printf("%s\n", code[3]);
                      if (strcmp(crypt(code, "50"), hash) == 0)
                      {
                          printf("%s\n", code);
                          return 0;
                      }
                  }
              }
          }
      }
  }
  </code></pre>