At DEF CON 2024, a CTF team spent three hours on a crypto challenge before realizing the flag was hidden behind a single-byte XOR cipher — something a one-liner could have cracked in seconds. Cryptography challenges are where CTF players either shine or stall. This post walks you through the most common cipher types and the exact attack methods that break them.
Caesar and Classical Substitution Ciphers
Caesar cipher is rotation — every letter shifts by a fixed number. It looks random until you recognize the pattern. If you see Ymnx nx ymj kqfl, your first instinct should be frequency analysis or brute-force rotation.
Python handles this in one line. Here’s a quick brute-force across all 26 rotations:
python3 -c "
ciphertext = 'Ymnx nx ymj kqfl: JFP{wjajwxj_nx_jfxd}'
for shift in range(26):
result = ''.join(
chr((ord(c) - 65 - shift) % 26 + 65) if c.isupper() else
chr((ord(c) - 97 - shift) % 26 + 97) if c.islower() else c
for c in ciphertext
)
print(f'Shift {shift:2d}: {result}')
"
Shift 5: This is the flag: EAK{reverse_is_easy}
Shift 5 produces readable English and a valid flag format. The moment you see a recognizable word like the or flag in the output, stop. That’s your answer.
For longer classical ciphers like Vigenère, use the Index of Coincidence to find the key length, then attack each position independently. The tool kasiski inside CyberChef automates this, or you can use vigenere-solver on GitHub to recover the key automatically.
XOR — The CTF Staple
XOR encryption is everywhere in CTF crypto. It’s fast to implement and weak when the key is short or repeated. Single-byte XOR is trivially broken by trying all 256 possible key bytes and scoring the output for English character frequency.
The tool xortool (plain-English: analyzes XOR-encrypted files and guesses key length and key bytes) is your fastest path here. Suppose you download a binary blob called mystery.bin from a CTF challenge at 192.0.2.47:
$ xortool -x mystery.bin
The most probable key lengths:
2: 8.1%
5: 18.4%
10: 36.7%
20: 12.3%
Key-length can be 10
$ xortool -l 10 -c 20 mystery.bin
Found key: 6b657973657373696f6e
Decoded key (ASCII): keysession
Output written to xortool_out/
$ cat xortool_out/000.out
CTF{xor_k3ys_4r3_w34k_wh3n_sh0rt}
The -c 20 flag tells xortool that the most common plaintext byte is 0x20 (space) — a solid assumption for English text. xortool recovered the full ASCII key keysession and dumped the plaintext. Flag in hand.
When xortool doesn’t converge, try -c 00 for binary files or manually inspect the output directory for the most readable file. Partial readability is still a lead.
RSA Weak Key Attacks
RSA challenges in CTFs almost never use properly generated keys. Organizers intentionally introduce weaknesses: small primes, shared prime factors across two public keys, tiny public exponents, or textbook RSA with no padding.
The go-to toolkit is RsaCtfTool — a Python script that runs a battery of known attacks against a public key automatically. If you’re handed a PEM file called pub.pem:
$ python3 RsaCtfTool.py --publickey pub.pem --uncipherfile flag.enc
[*] Testing key pub.pem.
[*] Performing factordb attack.
[*] Attack success with factordb !
Results for pub.pem:
Private key :
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA2a7N...
-----END RSA PRIVATE KEY-----
Plaintext : b'CTF{sm4ll_pr1m3s_k1ll_rs4}'
The factordb attack succeeded because the modulus N was composed of known small primes already catalogued at factordb.com. Once N is factored into p and q, computing the private key is arithmetic. No brute force needed.
If factordb misses, RsaCtfTool also runs Wiener’s attack (catches small private exponent d), Fermat factorization (catches primes that are close together), and common modulus attacks when two ciphertexts share the same N. Run it first, understand why it worked second.
Reading the Output Before Picking the Attack
Experienced CTF players don’t pick an attack at random. They read the challenge metadata carefully. If the ciphertext is all uppercase letters with no numbers, it’s classical. If it’s a hex blob, check for XOR. If you get a PEM file, go straight to RsaCtfTool.
When the encoding isn’t obvious, run file and xxd on whatever you’re given:
$ file mystery.bin
mystery.bin: data
$ xxd mystery.bin | head -4
00000000: 1b4c 1f49 1b59 0049 1b4f 0043 1b40 1b49 .L.I.Y.I.O.C.@.I
The repeating high-nibble pattern (1b appears constantly) is a textbook sign of single-byte XOR. That byte is likely your key — XOR 0x1b against space (0x20) gives 0x3b. Try it.
What To Do Now
Download the latest picoCTF practice archive and filter for Cryptography challenges rated Easy or Medium. Pick one, resist the urge to Google the solution, and work through it using xortool or RsaCtfTool first. The goal isn’t just getting the flag — it’s recognizing the cipher type from the raw output within two minutes. That instinct is what separates fast CTF solvers from slow ones.
