I'm stuck on pset2's Hacker Edition crack.c. I made this code after exploring various ideas for hours and it really makes sense to me but apparently the dumb computer can't really understand what I'm trying to say (sarcasm).
Can anyone elaborate what I'm doing wrong? The code compiles perfectly, but when I execute the file it like processes for a minute and so and then just returns me to my workspace like nothing happened. It does print out the newline tho.
Also I am aware of the fact that with this code I am only covering the all 4 letter combinations (meaning that I do not cover combinations with 1, 2 or 3 letters). However, this hash (50fkUxYHbnXGw) is 'rofl' encrypted and it still doesn't get printed out. Thanks.
#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h>
int main (int argc, string argv [])
{
const char *salt = "50";
if (argc != 2 ){
printf ("Bad job mate\n");
return 1;
}
char alphabet [] = {'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 result [4];
int i, j, k, l;
for (i = 0; i < 52; i++){
for (j = 0; j < 52; j++){
for (k = 0; k < 52; k++){
for (l = 0; l < 52; l++){
result [0] = alphabet [i];
result [1] = alphabet [j];
result [2] = alphabet [k];
result [3] = alphabet [l];
if (crypt (result, salt) == argv [1]){
printf ("%c%c%c%c", result [0], result [1], result [2], result [3]);
break;
}
}
}
}
}
printf ("\n");
return 0;
}