Free online courseInteractive · No sign-up · Works offline once loaded
CTF crypto for beginners
Your first steps in the crypto category of Capture the Flag. Interactive lessons show how text becomes bytes, how to spot and peel layers of encoding, how to break classical ciphers and how XOR keys give themselves away.
The course as text
Everything from the lessons in 7 short chapters, to read or to look something up later.
What a CTF is
A Capture the Flag competition, CTF for short, is a security game. The organizers publish challenges, each one hiding a secret string called the flag. It usually has a fixed format such as flag{…} or picoCTF{…}. You find it, submit it and get points. Most beginner CTFs are “Jeopardy” style: a board of challenges in categories like crypto, web, forensics, reverse engineering and binary exploitation, each worth more points the harder it is.
The crypto category is the friendliest place to start. Many easy challenges are not about breaking modern encryption at all. They wrap the flag in encodings and old ciphers: Base64, hex, ROT13, Caesar, XOR. Learning to recognize these layers is the first skill this course teaches.
One rule comes before everything else: only attack what the organizers explicitly allow. The challenge servers are in scope. The scoreboard, the infrastructure and other players are not, unless the rules say so.
Text is just bytes
Computers store text as numbers. In ASCII, the letter f is 102, l is 108, a is 97 and g is 103. The same number can be written in different bases: 102 is 66 in hex and 01100110 in binary. Hex, binary, octal and decimal “encodings” in CTFs are nothing more than these numbers written out.
Base64 packs bytes into 64 safe characters (A–Z, a–z, 0–9, + and /). It takes three bytes, 24 bits, and splits them into four groups of 6 bits. Each group picks one of the 64 characters. If the input is not a multiple of three bytes, = pads the end. That is why Base64 so often ends with one or two equals signs, and why its length is a multiple of four. Base32 does the same with 5-bit groups and only uses A–Z and 2–7.
Encoding is not encryption. There is no key: anyone who recognizes the format can turn it back. That is exactly what makes it a good first layer in a challenge.
Peeling layers
Easy crypto challenges stack encodings: the flag is ROT13'd, the result written as hex, the hex encoded as Base64. To solve it you go backwards, one layer at a time, and look at the result after each step. Does it look like another format? Peel again. Does it look like the flag format with scrambled letters? Try ROT13 or Caesar. Unreadable bytes? Think about XOR.
Some steps don't look like progress on their own. ROT13 on a string of hex characters gives letters like n–s, which are no longer hex. The other way round: ROT13 on that string turns it back into valid hex. That's the kind of hint to look for. The chain decoder does this search automatically and shows each step, and you can also peel by hand.
Classical ciphers
The Caesar cipher moves every letter by the same number of places. With only 25 possible shifts, you just try them all. In a CTF you know part of the plaintext: the flag prefix. If the ciphertext starts with mshn and the flag format is flag, the shift is the distance from f to m.
For longer texts, frequency analysis works for every single-alphabet substitution: in English, E, T and A are the most common letters. Count the letters of the ciphertext and line the peaks up with English.
Vigenère uses a keyword: each letter of the key gives the shift for one letter of the text, and the key repeats. That flattens the letter frequencies. To break it, find the key length first (the index of coincidence of every n-th letter jumps up at the right length), then solve each column like a Caesar cipher. The cipher tab does both.
XOR
XOR (exclusive or, written ⊕) compares two bits: the result is 1 if they differ and 0 if they are equal. Applied to bytes, every bit of the data is flipped where the key has a 1. The key property: XOR with the same key twice gives back the original, (m ⊕ k) ⊕ k = m. That's why XOR is everywhere in cryptography, and in CTFs.
With a single-byte key there are only 255 possibilities. Try them all and keep the one that gives readable text. With a longer, repeating key, use what you know about the plaintext: c ⊕ m = k. If the flag starts with flag{, XOR the first five bytes of the ciphertext with flag{ and you get the first five bytes of the key. If they repeat, you have the whole key. This is called a known-plaintext attack.
Real ciphers like AES are built so that this does not work. XOR with a short repeating key is not encryption you should ever use, but it is a classic challenge.
Knowing when to stop
Not every string is a layer. A hash such as MD5 or SHA-256 is a one-way fingerprint: there is nothing inside to decode. 32 hex characters after a decoding step are a strong sign that you reached a hash, not another layer, and the flag must come from somewhere else in the challenge. The same goes for real encryption like AES: without the key, no amount of decoding helps. Then the challenge is about finding the key, for example in the source code you were given.
Final check
That's the course. Next step: pick a beginner-friendly CTF. picoCTF runs all year with a practice area, and CTFtime lists upcoming events. Keep the CTF tools open in a tab: the chain decoder, the XOR key finder and the cipher cracker run in your browser, so nothing from the challenge leaves your device.
Words you will meet
- ASCII
- The table that gives every basic character a number from 0 to 127, e.g. A = 65.
- Base64
- An encoding that writes any bytes with 64 safe characters. No key, fully reversible.
- Brute force
- Trying every possible key until one works.
- CTF
- Capture the Flag: a security competition where you find hidden flags.
- Crib
- A piece of plaintext you know or guess, used to recover the key.
- Encoding
- A different way to write data. Not a secret: anyone can reverse it.
- Flag
- The secret string you submit for points, e.g. flag{…}.
- Frequency analysis
- Counting letters to break substitution ciphers.
- Hex
- Base 16: each byte as two characters from 0–9 and a–f.
- Index of coincidence
- How likely two random letters of a text are equal. About 0.066 for English.
- Jeopardy CTF
- A CTF with a board of challenges in categories, each worth points.
- Known-plaintext attack
- Using known plaintext and its ciphertext to work out the key.
- ROT13
- Caesar shift by 13. Applying it twice gives back the original.
- XOR
- Exclusive or: 1 where two bits differ. XOR with the same key twice cancels out.