Skip to main content
This section focuses on practical cryptography for offensive security and CTFs: how to quickly recognise common patterns, pick the right tools, and apply known attack templates. The goal is not to prove security proofs but to break things.

Quick classification workflow

When you encounter an unknown crypto challenge or sample:
  1. What is the primitive? Block cipher, stream cipher, hash, MAC, or public-key?
  2. What do you control? Plaintext oracle, ciphertext, key material, IV/nonce?
  3. What is leaked? Padding errors, timing differences, error messages, nonce reuse?
  4. Which mode/construction is used? ECB, CBC, CTR, GCM, RSA-PKCS1v1.5, etc.?

Toolchain setup

Symmetric crypto

Cipher Block Chaining (CBC)

Malleability, padding oracle attacks, bit-flip exploits.

Padding Oracle Attacks

Decrypt arbitrary ciphertext and forge messages without the key.

AES modes at a glance

ECB detection and exploitation

ECB encrypts each 16-byte block independently: equal plaintext blocks produce equal ciphertext blocks.
Cut-and-paste attack: craft a plaintext so a block containing admin aligns to a block boundary, encrypt it, then swap that ciphertext block into the position of the user field in a legitimate token.

CTR and GCM nonce reuse

If two messages are encrypted under the same key and nonce:
With any known-plaintext segment, the full keystream can be recovered for those offsets:

Hash attacks

Length extension

Many hash constructions (MD5, SHA-1, SHA-256) are vulnerable to length extension: given H(secret || message) and the length of secret, an attacker can compute H(secret || message || padding || extension) without knowing secret.
HMAC is immune to length extension attacks. Always use HMAC for message authentication, not a bare hash.

Hash cracking quick reference

Public-key crypto

RSA common mistakes

| Scenario | Attack | |---|---|---| | Small public exponent e=3, small message | Cube-root attack (no padding) | | Same message, different moduli, same small e | Coppersmith / Håstad broadcast | | Shared prime factor between two moduli | gcd(n1, n2) recovers p immediately | | Weak random — close primes | Fermat factorisation | | PKCS#1 v1.5 padding oracle | Bleichenbacher attack |

MAC forgery

CBC-MAC variable-length forgery

CBC-MAC is secure only for fixed-length messages. If an attacker obtains tags for two messages and can concatenate them, they can forge a tag for the concatenation without knowing the key.
Always use HMAC-SHA256 or AES-CMAC for variable-length message authentication.

Stream ciphers and XOR

Almost every stream cipher or custom encryption scheme reduces to:
With keystream reuse or known plaintext, decryption is trivial:
RC4: encrypt and decrypt are the same operation. If you have an encryption oracle, use it as a decryption oracle.
  • Trail of Bits — Carelessness versus craftsmanship in cryptography (2026)
  • Cryptopals challenges (cryptopals.com) — practical exercises covering all the above attacks
  • SageMath documentation — for lattice and ECC attacks