Hi everyone 🙂 Sorry, been busy with school/work, finally found some time to finish up my week 2 problem sets, took me a long time to figure out how to do the crack problem set.
I understood the concepts, and had it planned in my head, but to put it in codes was incredibly frustrating.
Here’s some tips to think about:
I was mostly having problem with how declare a variable that is 4 letters blank (not spaces). The problem is space is not equals to \0. I couldn’t declare 4 letter string with 1 letter and 3 spaces, or 2 letter 2 spaces.
The solutions is to control \0 points.
// declaring a variable that takes 5 slots (eventhough you only have 4 letter password, the last space is for \0, instead of using string, use char data type.
// then for control;
password = ‘\0’;
// This way, password is the letter you are testing, then use crypt(password, hash) to compare. Confused? Here’s an example, think of * as space. password A*** is not the same as A\0. Eventhough they both are visually the same.
The second problem I had was comparing my guess and the hash given. For unknown reason, I’m not able to do if (attempt == hash), I had to do loops if (attempt[i] == hash[i]). So C++ had me checking the hash character by character, instead of the whole string. I couldn’t understand why. Please comment if anyone understands or would like to see my partial code for the function?