The Caesar cipher explained: how it works and how to break it
The Caesar cipher replaces each letter with the letter a fixed number of places further along the alphabet, wrapping round from Z to A. With a shift of 3, A becomes D, B becomes E and Z becomes C. It is one of the oldest known ciphers and one of the easiest to break, because there are only 25 possible shifts and letter frequencies give the answer away. The Caesar cipher tool encodes, decodes and cracks it, and this guide works through how.
How the shift works
Write the alphabet out, then write it again shifted along by the key. With a shift of 3:
- Plain: A B C D E F G ... W X Y Z
- Cipher: D E F G H I J ... Z A B C
To encrypt, find each letter in the top row and replace it with the one below; to decrypt, go the other way, which is the same as shifting forward by 26 minus the key. Mathematically, number the letters A=0 to Z=25 and the ciphertext letter is the plaintext letter plus the key, modulo 26. The cipher takes its name from Julius Caesar: the Roman historian Suetonius records that he used a shift of three for confidential messages, and that his nephew Augustus used a shift of one.
A worked example
Encrypt ATTACK AT DAWN with a shift of 3. A moves three places to D, T to W, C to F, K to N, W to Z and N to Q. The result is DWWDFN DW GDZQ. Caesar's most famous phrase, VENI VIDI VICI, becomes YHQL YLGL YLFL. Notice what survives the encryption: word lengths, spaces, and repeated letters. The double T in ATTACK is still a double W. Those leftovers are exactly what a codebreaker uses. In the tool, set the slider to 3, type your text, and the result updates as you type; the Use result as input button lets you shift again or check the decode.
ROT13: the shift that undoes itself
A shift of 13 is special. Because 13 is half of 26, shifting by 13 twice brings every letter back to where it started, so the same operation both encrypts and decrypts: HELLO becomes URYYB, and URYYB becomes HELLO. ROT13 became popular on Usenet in the early 1980s for hiding joke punchlines and spoilers, where the aim was never secrecy, just to stop someone reading the answer by accident. The tool has a one-click ROT13 button.
How to break it
There are two easy attacks. The first is brute force: there are only 25 useful shifts, so you simply try them all and see which one produces readable text. The tool does this automatically and lists every shift.
The second, more elegant method is frequency analysis, first described by the Arab scholar al-Kindi in the ninth century. Letters in a language appear at characteristic rates: in English, E is the most common, at roughly one letter in eight, followed by T and A. A Caesar shift moves those peaks without flattening them, so the most common letter in a long ciphertext is probably E shifted. The tool scores each shift by comparing its letter counts with normal English frequencies using a chi-squared test, and stars the best match. On very short messages the statistics are weak and it can guess wrong, but brute force still works. Word patterns help too: a one-letter word is almost always A or I.
What it is still good for
The Caesar cipher offers no security at all, but it is a good puzzle, a classic geocaching clue and a clear way to teach modular arithmetic. A stronger hobby cipher replaces each letter with any other letter rather than a fixed shift, which gives about 4 times 10 to the power 26 possible keys; the cryptogram maker builds those puzzles, and frequency analysis still breaks them. The Vigenère cipher combines several Caesar shifts with a keyword and held out for centuries, as The Vigenère cipher explained: keyword encryption and how it was broken describes. For anything that genuinely needs protecting, use modern encryption such as the AES-based message encryption tool; Hashing, encryption and encoding explains what modern methods do differently.
Sources and further reading
The claims in this guide rest on these references, which were checked when the guide was last updated. Spotted an error? The contact page says how to report it.