, , , , , , , ,

Course: Harvard’s CS50

Problem Set 2: Crypto

pset2/hacker2 is an assignment with two goals:

  1. Learn how strings work in C.
  2. Learn some fundamental encryption methods while doing (1).


Print a silly song.

oldman.c (view | download)


Learn about the Caesar cipher.

caesar.c (view | download)


Learn about the Vigenère cipher

vigenere.c (view | download)

Crack (hacker2)

This is a free-form assignment. Write a des56 password cracker. Design and implementation decisions are left up to you.

I originally wrote a simple version for this assignment that just brute-forced using a hard-coded character set. Something like that should be enough to satisfy the requirements. In fact due to the way they automatically ‘test’ submitted solutions anything more complicated than that may be beyond the scope of the assignment.

However, long after I wrote the first version (and after the end of the course) I went back, poked and prodded and changed the hell out of it and the result is not just a simple implementation any more. It’s something one might actually use in real life.

Uses getopt to get the cli parameters. Options: a dictionary file for a dictionary attack; can specify upper limit of brute force attack; can choose from predefined charsets to brute force with, or specify one.

crack.c (view | download) Note: it is not compatible with the problem set’s specs.


This version of vigenere encodes and decodes text.

vigenere2.c (view | download) Note: it is not compatible with the problem set’s specs.

If you plan to tackle hacker2, you’re sure to need to make your own des56 keys, from simple passwords like ‘abcd’, so your brute force attack can find the solution fast while you debug.

testcrypt.c (view | download)