SPOILERS (maybe)
Hi, I have just started working on crack. I have no previous experience, at least not too much but I'm trying to grasp the logic behind this and it seems my biggest issue for this is pointers (or rather ignoring their existence for crypt)
What I figure out could potentially work is:
1) check if there are 2 arg
2) declare an array of all letters of the alphabet (I was thinking this may be unnecessary and taking unnecessary space but to simplify it for now - baby steps - I decided to do so)
3) iterate through the array (4 nested loops for 1, 2, 3 and 4 letters passwords) while checking if the output of crypt with same salt and my current guess is same as the hashed password.
I started writing the loops but after I wanted to test it for 1 letter first it did not wanted to compile (pointers I think).
This is the relevant fragment of my code (with 1 loop only for now):
//Declare an array of all the letters in the alphabet
char letters[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'};
string hashed = argv[1];
char salty[3] = {hashed[0], hashed[1], '\0'};
string salt = salty;
for (int i = 0; i < 52; i++)
{
if (crypt(letters[i], salt) == argv[1])
{
printf("Password: %s\n", letters[i]);
}
}
This is what I (not surprisingly) get from clang:
warning: incompatible integer to pointer conversion passing 'char' to parameter of type 'const char *'; take the address with & [-Wint-conversion]
if (crypt(letters[i], salt) == argv[1])
^~~~~~~~~~
&
/usr/include/crypt.h:32:33: note: passing argument to parameter '__key' here
extern char *crypt (const char *__key, const char *__salt)
^
warning: format specifies type 'char *' but the argument has type 'char' [-Wformat]
printf("Password: %s\n", letters[i]);
~~ ^~~~~~~~~~
%c
I know it may be a lot to ask for but could anybody explain to me what should I do with this? Just a hint would be great I wanna use this as a learning experience.
Thank you.