On my quest to solve Crack, came up with a couple questions:
- How do I know when to use strcmp(s1, s2)? How do I know when I'm comparing memory addresses and when I'm comparing the actual contents of my strings?
I had something like this:
if (hashedGuess == givenHash) { printf("%s\n"); }
But, even though the two string looked exactly the same, this would never evaluate to True. I learned to use the strcmp() function, and it worked. But how do I know when to use it?
- Do I need to explicitly state NULL ("\0") in my array?
There has to be a prettier way than this:
char passwordGuess[5] = { '\0', '\0', '\0', '\0', '\0'};
This worked, but looks like it might be a little amateurish.
- Are the elements of my array full of data before I use it?
I originally defined the above array as:
char passwordGuess[4];
This would cause me to generate different hashes every time, obviously making it impossible to crack anything. I know now that I didn't leave an extra element for the NULL terminator (correct terminology?). But, even when I was just dealing with the 0th element, I would get different hashes. Is there some random data in the empty elements throwing crypt() off eveytime I use it? Why did I get different hashes every time? Shouldn't the output of crypt() be the same?
- This is ugly! What's a better way?
char passwordAlphabet[52] = {'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'};
EDIT: Yes! this is better: char passwordAlphabet[] = {"ABCDEFGHIJKLMNOPQRSTUXWXYZabcdefghijklmnopqrstuvwxyz"};
Again, this worked. I didn't want to iterate over ASCII values directly because I felt I would be wasting computations on the non-Alpha chars between 'Z' and 'a'. It also felt easier to structure my for-loops to iterate 52 times (number of elements in my array). Is there a better way to define this array? Is there a better technique that I'm not using?
I didn't post my source because I wasn't sure if it would be considered posting a solution, which is unethical.