🔐

Cryptography

Crypto challenges require you to break ciphers, identify weaknesses in custom implementations, and exploit mathematical flaws in everything from Caesar shifts to RSA, elliptic curves, and stream ciphers.

What is it?

Cryptography is the science of securing information through mathematical transformations. It underpins everything from HTTPS and password storage to digital signatures and end-to-end messaging.

In security, the goal is often the opposite — breaking cryptographic schemes that are poorly designed or incorrectly implemented. Even mathematically sound algorithms can be vulnerable when developers misuse them.

How it works in a CTF

In a CTF, you receive ciphertext, a public key, an encryption oracle, or a custom encryption script and must recover the plaintext flag. Challenges test your ability to spot mathematical weaknesses, abuse implementation mistakes, or apply known academic attacks.

Common workflow: identify the algorithm → check for known vulnerabilities (e.g. small RSA exponent, reused IV) → apply the appropriate mathematical attack using Python/SageMath → decrypt the flag.

Example challenge types
RSA small-exponent attack (e=3)Repeating-key XORCBC bit-flippingPadding oracle (PKCS#7)Hash length extensionECDSA nonce reuse (k-reuse)Wiener's RSA attack (small d)AES-ECB mode (detect repeated blocks)Vigenère / frequency analysisDiffie-Hellman small subgroupCommon-modulus RSA attackSubstitute classical cipher (Caesar, ROT13)

Sample Challenge

Tiny Exponent
Crypto Easy 100 pts
You intercepted an RSA-encrypted message sent to three different recipients, all sharing the same public exponent e = 3. You have the three ciphertexts c1, c2, c3 and their corresponding moduli n1, n2, n3. The plaintext is short enough that m³ < n1·n2·n3.
challenge.pyoutput.txt
How to solve it
  1. Recognise the setup: same message, same e=3, three different moduli — this is Håstad's broadcast attack.
  2. Compute C = CRT([c1,c2,c3], [n1,n2,n3]) using the Chinese Remainder Theorem in Python (sympy.crt or manual implementation).
  3. Take the integer cube root of C: m = iroot(C, 3).
  4. Convert the integer m to bytes: long_to_bytes(m) from the Crypto.Util.number module.
FLAG{h4st4d_br04dc4st_3=3}

Getting Started Tips

💡 Tip: If the challenge gives you ciphertext and a key, identify the algorithm first. CyberChef's 'Magic' tool can detect many schemes automatically.
💡 Tip: For RSA: always check for small exponent (e=3), common factor attacks, LSB oracle, Wiener's attack, or unpadded textbook RSA.
💡 Tip: CryptoPals sets 1–4 are universally recommended even if you are experienced — they build essential attack intuition.
💡 Tip: Learn basic Python number theory: Modular inverse (pow(a,-1,n) in Python 3.8+), GCD (math.gcd), and factor via sympy.