-1
#include <cs50.h>
#include <crypt.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define _XOPEN_SOURCE

int main(int argc, string argv[])
{
   if (argc != 2)
   {
      printf("error\n");
      return 1;
   }

   char salt[] = {argv[1][0], argv[1][1]};

   string hash = argv[1], letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

   char pass1[2];
   pass1[1] = '\0';
   for (int j = 0; j < 52; j++)
   {
      pass1[0] = letter[j];
      if (strcmp(hash, crypt(pass1, salt)) == 0)
      {
         printf("%s\n", pass1);
         return 0;
      }
   }

   char pass2[3];
   pass2[2] = '\0';
   for (int i = 0; i < 52; i++)
   {
      pass2[0] = letter[i];
      for (int j = 0; j < 52; j++)
      {
         pass2[1] = letter[j];
         if (strcmp(hash, crypt(pass2, salt)) == 0)
         {
            printf("%s\n", pass2);
            return 0;
         }
      }
   }

   char pass3[4];
   pass3[3] = '\0';
   for (int i = 0; i < 52; i++)
   {
      pass3[0] = letter[i];
      for (int j = 0; j < 52; j++)
      {
         pass3[1] = letter[j];
         for (int k = 0; k < 0; k++)
         {
            pass3[2] = letter[k];
            if (strcmp(hash, crypt(pass3, salt)) == 0)
            {
               printf("%s\n", pass3);
               return 0;
            }
         }
      }
   }
}
1
  • When posting code, you can select it and press the {} button in the editor or Ctrl+K to add four spaces in front of each selected line. Four spaces in front of each line is interpreted as a code block, that way the # or * or _ inside your code are not mistaken for markdown. – Blauelf Feb 5 '18 at 17:24
1
for (int k = 0; k < 0; k++)

This loop will never be entered, as initial value 0 is not <0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .