Skip to main content
CTFWorld
CryptoDifficulty: Beginner -> Elite

Cryptography

CTF cryptography rarely asks you to brute-force AES-256. Instead, you diagnose subtle implementation mistakes—reused nonces, small RSA exponents, predictable PRNGs, CBC padding oracles, or weak elliptic curves—and recover plaintext or private keys mathematically.

Core Attack Classes & Concepts

Encoding, Classical Ciphers & XOR

Distinguishing encodings from encryption and breaking repeating-key XOR or substitution schemes.

Key Techniques: Known-plaintext crib dragging (e.g., "ctfworld{"), frequency analysis, and Hamming distance key-length detection.

Block Cipher Modes & Oracles

Attacking ECB block shuffling, CBC bit-flipping, padding oracles, and CTR/GCM nonce reuse.

Key Techniques: Byte-at-a-time ECB decryption, PKCS#7 padding oracle recovery, and GCM forbidden attack (GHASH key recovery).

RSA & Public-Key Pitfalls

Factoring weak moduli or recovering plaintext when parameters violate safe bounds.

Key Techniques: Small e cube root, Hastad broadcast, Fermat/Pollard p-1 factoring, Wiener’s attack, and Coppersmith small roots.

Hashes, MACs & Signatures

Forging authenticated messages or recovering ECDSA private keys from biased nonces.

Key Techniques: SHA-256 length extension, ECDSA nonce reuse (k recovery), Bleichenbacher signature forgery.

PRNGs, Elliptic Curves & Lattices

Cloning Mersenne Twister states, Pohlig-Hellman on smooth curves, and LLL lattice basis reduction.

Key Techniques: MT19937 state recovery from 624 outputs, Smart’s attack on anomalous curves, Hidden Number Problem with LLL.

Competition Methodology Checklist

  1. 1

    Read the entire cryptosystem source line by line and list every secret, public value, and oracle available to you.

  2. 2

    Check the classics first: reused IV/nonce, small public exponent, shared prime factors (GCD), or unauthenticated ciphertext.

  3. 3

    Separate encoding noise (Base64, hex, zlib) from actual cryptographic primitives before writing math.

  4. 4

    Prototype your attack locally with known keys so you can verify equations before querying the live server.

  5. 5

    Reach for SageMath when tackling polynomials over finite fields, elliptic curves, or lattice reductions.

Reference Pattern

Known-Plaintext Repeating-Key XOR Recovery
python
ciphertext = bytes.fromhex('08111f1c0a0b070102')
known_prefix = b'ctfworld{'
recovered_key = bytes(c ^ p for c, p in zip(ciphertext, known_prefix))
print('Derived key bytes:', recovered_key)  # b'keykeykey'

Because XOR is self-inverse (C ⊕ P = K), a known flag prefix immediately leaks a repeating keystream.

Recommended Practice Progression

Challenge / TrackPlatformLevelFocus
Introduction & Modular ArithmeticCryptoHackBeginnerBest-in-class interactive modern cryptography track
Set 1 & Set 2: Basics & Block CryptoCryptopalsBeginnerXOR, ECB detection, CBC padding oracle from scratch
RSA & Diffie-Hellman CoursesCryptoHackIntermediateReal-world public-key failure modes
Lattice & Elliptic Curve ChallengesCryptoHackAdvancedLLL, Coppersmith, and invalid-curve attacks

Defensive Engineering Takeaway

Never roll custom crypto; use vetted AEAD schemes (AES-GCM / ChaCha20-Poly1305) with unique CSPRNG nonces, constant-time comparisons, and modern libraries like libsodium or Tink.