The Matasano crypto challenges

Answers, by Stuart Langridge

The Matasano crypto challenges are a set of increasingly difficult coding challenges in cryptography; not puzzles, but designed to show you how crypto fits together and why all the parts are important. Cheers to Maciej Ceglowski of for bringing them to my attention.

Here I'll attempt to provide solutions in JavaScript, from first principles — that is, I will not use built-in features of the language, but build it all up from the basics. I also have no interest in being efficient here; I'll take slow plodding steps to an answer; in particular, I do a bunch of stuff by acting on individual bits, even though JS has much better facilities for XORing a whole bunch of stuff at once or whatever.

Set 1, challenge 1: Convert hex to base64

The string: 49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d should produce SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t.

Set 1, challenge 2: Fixed XOR

The string: 1c0111001f010100061a024b53535009181c xored with 686974207468652062756c6c277320657965 should produce 746865206b696420646f6e277420706c6179.

Set 1, challenge 3: Single-byte XOR cipher

The string: 1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736 has been xored with a single byte from an English message.

Set 1, challenge 4: Detect single-character XOR

One of the 60-character strings in the file has been encrypted by single-character XOR.

Set 1, challenge 5: Implement repeating-key XOR

The string:

Burning 'em, if you ain't quick and nimble
I go crazy when I hear a cymbal

when XORed with repeating key "ICE", should equal


Set 1, challenge 6: Break repeating-key XOR

Break the encoded file, which is base64ed after being encrypted with repeating key XOR.