I have been scratching my head quite a lot here and couldn't find a solution. I have written this code in order to crack simple 4 characters passwords (see code below). I can see that the passwords are correctly generated and that every possibility is tested with every combination of letters from A to z but the loop is never ending. Could someone tell me why?
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <crypt.h>
int main(int argc, string argv[])
{
//check number of arguments
if( argc != 2 )
{
printf("Usage: ./crack hash\n");
}
char str[5];
char salt[] = "..";
strncpy(salt, argv[1], 2);
string hash = argv[1];
string password = "....";
char pass[5];
//brute force loop
for( int i = 65; i < 123; i++)
{
str[0] = i;
for( int j = 65; j < 123; j++)
{
str[1] = j;
for( int k = 65; k < 123; k++)
{
str[2] = k;
for( int l = 65; l < 123; l++)
{
str[3] = l;
str[4] = '\0';
strcpy(pass, str);
password = crypt(pass, salt);
if ( hash == password)
{
printf("%s\n", password);
break;
}
printf("\r%s", pass);
fflush(stdout);
}
}
}
}
}