Caesar Cipher: How It Works, Examples and How to Break It
What is the Caesar cipher?
The Caesar cipher is one of the oldest and simplest encryption techniques in the world. It is a type of substitution cipher in which every letter in the plaintext is replaced by a letter some fixed number of positions further down the alphabet. For example, with a shift of 3, the letter A becomes D, B becomes E, and so on. When the shift reaches the end of the alphabet, it wraps around: X becomes A, Y becomes B, Z becomes C.
A short history
The cipher is named after Julius Caesar, the Roman general and statesman who reportedly used it around 58 BC to protect military communications. Caesar used a shift of 3 for his private correspondence. At the time, most of his enemies were illiterate, so a simple substitution was enough to keep messages secret. Today the cipher is studied mostly as an introduction to cryptography.
How encryption works, step by step
Let us encrypt the word HELLO with a shift of 3.
- Write the plaintext: H E L L O.
- Shift each letter three positions forward in the alphabet.
- H → K, E → H, L → O, L → O, O → R.
- The ciphertext is KHOOR.
Decryption reverses the process: shift each letter of the ciphertext three positions back to recover HELLO.
The formula
If we number the letters A=0, B=1, …, Z=25, the encryption of a letter x with shift n is:
E(x) = (x + n) mod 26
Decryption is the inverse:
D(x) = (x − n + 26) mod 26
The "mod 26" part is what makes the alphabet wrap around. Without it, shifting Z by 3 would push us past the end of the alphabet.
How decryption works
Because the Caesar cipher is symmetric, decryption uses the same idea as encryption but with a negative shift. If you know the key n, you simply subtract n from each letter. If you do not know the key, you need cryptanalysis, which we cover next.
Why it is insecure
The Caesar cipher has only 25 useful keys, because a shift of 0 or 26 leaves the message unchanged. That means an attacker only has to try 25 possibilities to recover the plaintext. Modern computers do this in microseconds, and even a human can do it by hand in a few minutes.
A second weakness is that the cipher preserves letter frequency. In English, E, T and A appear far more often than Q, X and Z. If the letter H appears most often in the ciphertext, the attacker can guess that H actually represents E, which immediately reveals the shift.
How brute force breaks it
Brute force simply means trying every possible key. Because there are only 25, you can write out all 25 decryptions of a message and pick the one that reads like English. The Securnix brute force analysis panel does exactly this: it tries all shifts and scores each result by how closely it resembles natural English, using common words and letter frequencies.
ROT13: a special case
ROT13 is a Caesar cipher with a shift of 13. It is special because applying ROT13 twice returns the original text: 13 + 13 = 26, which is a full cycle. ROT13 is not used for security. It is used online to hide spoilers, puzzle answers, and offensive content from casual readers. It is a good example of why a fixed, well-known shift offers no real protection.
Real-world uses today
The Caesar cipher has no place in modern security, but it is still useful in a few contexts. It is a standard first lesson in cryptography courses because it introduces the ideas of keys, encryption, decryption, and cryptanalysis. It appears frequently in puzzles, escape rooms, and CTF competitions. And it lives on in ROT13 as a simple obfuscation tool.
Frequently asked questions
What is the Caesar cipher?
The Caesar cipher is a substitution cipher in which each letter in the plaintext is shifted a fixed number of positions down the alphabet.
Who invented the Caesar cipher?
It is named after Julius Caesar, who used it around 58 BC to protect military messages.
How many keys does the Caesar cipher have?
It has only 25 useful keys, since a shift of 0 or 26 leaves the message unchanged.
Is the Caesar cipher still used today?
It is not used for real security, but it is still taught in classrooms, used in puzzles, and appears in ROT13 for obfuscating text online.
How do you break a Caesar cipher?
You can break it by brute force, trying all 25 shifts and picking the readable output, or by frequency analysis of common letters like E, T and A.
Continue learning with the Playfair cipher guide, RSA encryption guide, or the cryptography beginner guide.