Crack compiles, but when I run it, nothing happens (I know the code isn't pretty, but I couldn't find the fault). It doesn't return anything, doesn't even stop. Thanks in advance! p.s. Sorry for the weird format, can't figure out how to change it
#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <crypt.h>
int main (int argc, string argv[])
{
if (argc!=2)
{
printf("usage: ./crack hash");
return 1;
}
string hash = argv[1];
//gets input
char salt[2];
char key[4];
key[0] = 65;
salt[0] = hash[0];
salt[1] = hash[1];
while(key[0]<123)
{
if (key[0]>90)
{key[0] = 97;}
string temp = crypt(key, salt);
if (temp == hash)
{
printf("%s\n", key);
return 0;
break;
}
key[0]++;
}
//checks 1 digit passwords
key[0] = 65;
key[1] = 65;
while(true)
{
if (key[0]>90)
{
key[0]=97;
}
if (key[1]>90)
{
key[1]=97;
}
string temp = crypt(key, salt);
if (temp == hash)
{
printf("%s\n", key);
return 0;
break;
}
key[1]++;
if(key[1]>122)
{
key[0]++;
key[1]= 65;
}
if (key[0]>122)
{
break;
}
}
//checks 2 digit passwords
key[0] = 65;
key[1] = 65;
key[2] = 65;
while(true)
{
if (key[0]>90)
{
key[0]=97;
}
if (key[1]>90)
{
key[1]=97;
}
if (key[2]>90)
{
key[2]=97;
}
string temp = crypt(key, salt);
if (temp == hash)
{
printf("%s\n", key);
return 0;
break;
}
key[2]++;
if(key[2]>122)
{
key[1]++;
key[2]= 65;
}
if (key[1]>122)
{
key[0]++;
key[1]= 65;
}
if (key[0]>122)
{
break;
}
}
//checks 3 digit passwords
key[0] = 65;
key[1] = 65;
key[2] = 65;
key[3] = 65;
while(true)
{
if (key[0]>90)
{
key[0]=97;
}
if (key[1]>90)
{
key[1]=97;
}
if (key[2]>90)
{
key[2]=97;
}
if (key[3]>90)
{
key[3]=97;
}
string temp = crypt(key, salt);
if (temp == hash)
{
printf("%s\n", key);
return 0;
break;
}
key[3]++;
if(key[3]>122)
{
key[2]++;
key[3]= 65;
}
if(key[2]>122)
{
key[1]++;
key[2]= 65;
}
if (key[1]>122)
{
key[0]++;
key[1]= 65;
}
if (key[0]>122)
{
printf("error\n");
break;
}
}
//checks 4 digit passwords
}