0

i have a hard time understanding the crypt function and since there aren't any technical details of how it works out there, i tested it and i observed that it is producing the same hash for different but similar words. i did some testings and this is what is happening.

hi = crypt("academics", "50");
hii = crypt("academicians", "50");

printf("academics : %s\n", hi);
printf("academicians : %s\n", hii);
printf("string compare : %d\n", strcmp(hi,hii));

output :

academics : 50IlqAh9rdDJo
academicians : 50IlqAh9rdDJo
string compare : 0

how do we suppose to find the password if we can't compare valid hashes..

1 Answer 1

0

You are assuming that the pointer to the string "hi" and "hii" are different. See here GNU C Library - crypt

RETURN VALUE Upon successful completion, crypt() shall return a pointer to the encoded string. The first two characters of the returned value shall be those of the salt argument. Otherwise, it shall return a null pointer and set errno to indicate the error.

So a question would be; What is the pointer that the crypt() function is returning? I suggest you reorder your code a bit, run again, and check results.

Second. For the crypt algorithm, using DES based algorithm as we are in the crack pset, only the first 8 characters are considered for the generated text. So you kind of set yourself up for double trouble. I added a third string to be passed to crypt just so you see.

I hope this helps.

hi = crypt("academics", "50");
printf("academics : %s\n", hi);

hii = crypt("academicians", "50");
printf("academicians : %s\n", hii);
printf("string compare : %d\n", strcmp(hi,hii));

different = crypt("notacademics", "50");
printf("notacademics : %s\n", different);

// Added just for fun
printf("address of hi == address of hii? %s\n", hi == hii ? "true" : "false");

You must log in to answer this question.

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