I’ve been messing around with some basic cryptography challenges ever since DEFCON, which was a ton of fun and very informative. The most recent challenge involved breaking a Vigenere cipher (also known as a repeating key XOR).

Here’s the basic algorithm:

A screen shot of me breaking a Vigenere cipher. Nothing informative here. I just felt like I looked like Hackerman while doing this. I’m highly caffeinated right now!

  1. Calculate normalized Hamming distances for various key sizes, and take the smallest one.
  2. Chunk cipher text into key-sized chunks.
  3. Transpose the chunk bytes.
  4. Find the single-byte XOR key for each transposed chunk with frequency analysis.
  5. Concatenate the keys, and find your plain text.
  6. ???
  7. Profit!

Fun stuff! So satisfying to see the plain text at the end of a challenge.

Here’s some of the code I wrote to do all of this (minus the profiting part): egyptiankarim/matasano