2/16/2025
Cryptopals #3 - Single-byte XOR Cipher
Cryptopals challenge 3 first provides a hex-encoded string and tells the programmer 'Find the key, decrypt the message.' They give a hint to devise a method to score a decrypted string and that, once completed, the programmer can make 'ETAOIN SHRDLU' jokes on Twitter. This all suggests frequency analysis to be the way forward
ETAOIN SHRDLU are the most frequently used letters in the English language and refers to a practice in an earlier era of publishing. When setting up the type for a newspaper, those letters formed the first two columns of available letters. If a mistake were made, rather than spending time sorting out the incorrect letter, the operator would simply run a finger down the first two columns, resulting in ETAOIN SHRDLU and acting as a flag to remove the line entirely. Sometimes, the operators would miss the flag and ETAOIN SHRDLU would make it into print.
The challenge itself calls for the programmer to try every key possible and generate a score using frequency analysis to judge if the decrypted text resembles English. There are a few things to consider: frequency of the letters themselves (ETAOIN SHRDLU), frequency of spaces and punctuation, and existence of non-printable characters. When scoring, I gave points for frequent letters and punctuation and penalized for non-printable characters.You can see my solution here