rgoussu@goussu: ~/library/security/exercises
~/library/security/exercises cat cryptopals-crypto-challenges.md

Cryptopals — crypto challenges (sets 1–3)

# Implement then break real cryptography — XOR, AES modes, the padding oracle — the staged project that makes "just use a library" a lesson learned, not a slogan.

Exercisesaved 2026-08-08source #cryptography#security#encryption#exercise#aes

Goal

Work the first three Cryptopals sets as a staged project: build the primitives from bytes up, then attack them. By the end you have broken single- and repeating-key XOR, distinguished and decrypted AES modes, and executed a CBC padding-oracle attack — proving in your own hands why nonce reuse, missing authentication, and home-rolled modes are catastrophic, and why the boring library answers exist.

Subject: full brief & instructions

Practices

Milestones

  1. Set 1 — basics. Hex↔base64, fixed XOR, single-byte XOR cipher (score plaintext by letter frequency), detect single-char XOR in a file, break repeating-key XOR (Hamming-distance keysize search), and decrypt AES-128-ECB with a library. Each is independently shippable and testable against the provided fixtures.
  2. Set 2 — block crypto. Implement PKCS#7 padding, CBC mode by hand on top of a raw ECB block function, write an ECB/CBC detection oracle, then mount the byte-at-a-time ECB decryption attack (simple, then with a random prefix).
  3. Set 3 — the payoff attack. Build the CBC padding-oracle attack end to end and recover plaintext with no key — the milestone that permanently changes how you read "encryption without integrity". Add CTR mode and break fixed-nonce CTR.
  4. Write up the lessons. For each attack, note the one design rule that would have prevented it (authenticate with AEAD, never reuse a nonce, pad-check in constant time).

Stretch goals

  • Continue into set 4 (stream-cipher/CTR and MAC attacks) and set 5 (Diffie-Hellman, RSA).
  • Re-implement one broken construction correctly with libsodium/Tink and show the attack now fails.

Related