Cryptopals Set 1 #1–2 — Hex/Base64, Fixed XOR
Cryptopals 1.1 looks trivial: write hex-to-base64. The reason it isn't is that the only-libraries-allowed rule means you write the encoding by hand once, then never again. The output of this challenge is a buffer-conversion utility you'll keep using through Set 4.
Quest Convert a hex string to base64 (no library calls); XOR two equal-length buffers.
Press Run.
Load-bearing idea
These two challenges teach a single thing: cryptographic buffers are bytes, not strings, and the encoding you display them in is a presentation choice that has nothing to do with the security argument. Hex and base64 are different ways of pointing at the same underlying byte string. XOR operates on bytes, not on characters.
If you mix presentation and substance — for example, by XOR-ing two hex strings character by character — you are doing the wrong thing in a way that will eventually quietly break a security proof. Set the boundary cleanly here, week one of the cryptopals track.
Retrieval prompts
- Why is base64 used in cryptographic protocols rather than hex, despite hex being human-readable?
- What is the relationship between the byte length of plaintext and the character length of its base64 encoding?
- Write the XOR of
b'\x00' * nand any byte stringsof lengthn. (Trivial, but the reason it’s trivial matters.)
Re-derivation log
After completing 1.1 and 1.2, write a one-paragraph note on what makes the cryptopals difficulty curve gentle here. Set 1 #3 (single-byte XOR cipher) takes the gloves off; Set 1 #4 (detect single-byte XOR) requires an actual scoring function. Note here what scoring function you’ll use and why.