I'm on the crack challenge from pset2 and I don't understand how to compile the program.

When I use

clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow crack.c -lcrypt -lcs50 -lm -o crack

as suggested (in the directory of crack) -nothing happens with no arguments. If I give arguments this error appears

clang: error: no such file or directory: '22'

And when I try to compile it with standard make method - the crypt() function doesn't seem to work.

Speaking of which - I can't quite understand how it works, man crypt and problem explanation is quite obscure to me. Could you please give me a hint or, maybe, something to watch or read on the subject.

  • When you compile it with clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow crack.c -lcrypt -lcs50 -lm -o crack does it create the crack output file? If so, what happens when you run ./crack? – robert_x44 Aug 29 '17 at 19:47
  • I already have crack output file. Now the compile seems (?) to be working. I'm not quite sure though as I don't quite understand how crypt() works. – Vasilii Vakhtin Aug 29 '17 at 20:07

crypt() is an encryption algorithm. It takes a plaintext string (a user password), and encrypts it, so that it can be stored in a file.

char *crypt(const char *key, const char *salt)

The key argument is the password to be encrypted, and salt is a two character string that 'tweaks' the algorithm's output. The output is a 13 character string. The first two characters are the salt that was passed in, and the next 11 characters are the encrypted password.

You know what salt to use by inspecting the encrypted password (all of the samples on the problem page start with 50). Your job is to guess key values (user passwords) until you find the right one. If calling crypt on your guessed key and the given salt results in a string that matches the input to the program, you have successfully cracked the password.

You can use the function like this:

string s = crypt(password, salt);

where password and salt are both strings.

Now you can use string functions (like strcmp) to compare the result to the input to the program (an encrypted password).

| improve this answer | |
  • Thanks, that cleared things out a bit. And what does "*" mean - like in "*crypt", "*salt" etc? – Vasilii Vakhtin Aug 29 '17 at 21:12
  • The * means the return type of the function is char* instead of char. Basically it's a string. The later lessons on pointers will explain this in depth. I've added code to the answer on how to use the return type. The type string is basically just an alias for char*. – robert_x44 Aug 29 '17 at 21:23
  • Thanks! And if I want to print this "char*" I have to do this, right?: char* casterisc = "foo bar baz"; printf("Print char* %c", casterisc); – Vasilii Vakhtin Aug 29 '17 at 23:02
  • @VasiliiVakhtin printf("%s", casterisc) to print a string, or printf("%c", casterisc[0]) to print a character in the string. – robert_x44 Aug 29 '17 at 23:48

You must log in to answer this question.

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