Skip to content
Explainer · Codes & Ciphers Lab

Classic Ciphers: Caesar, ROT13, Atbash and Affine

How the Caesar, ROT13, Atbash, affine and keyword ciphers work, how to crack them by counting letters, and why none of them is secure today.

4 min readPublished

People have been hiding messages in plain sight for over two thousand years. The earliest tricks swap each letter for another by a fixed rule. They are fun to use and a perfect starting point for cryptography, but each one falls to a patient attacker with a pencil. This guide shows how five classic ciphers work and why none can protect you now.

Plaintext, ciphertext and keys

The original message is the plaintext. The scrambled version is the ciphertext. A cipher is the rule that turns one into the other, and the key is the secret detail that picks exactly which scramble to use.

A good habit, which dates from the 1800s, is to assume the enemy knows the cipher's method and that only the key is secret. Everything below should be judged by that standard: if someone knows what you did but not your key, can they still read your message?

Caesar shift: slide the alphabet

The Caesar shift slides each letter forward by one fixed amount. Use a shift of 3 and A is written as D, B as E, while Z loops back to C. The Roman writer Suetonius reports that Julius Caesar used this on military letters.

The number of places is the key. Anyone who knows it can shift back. The trouble is how few keys there are: only 25 useful shifts exist. An attacker can simply try them all, a brute-force search that takes a minute by hand and no time at all on a computer.

ROT13

ROT13 locks the Caesar shift at 13 places. Since the alphabet is 26 letters long, two shifts of 13 bring you back to the start. Encrypting and decrypting are the same operation. Forums used it to hide spoilers because it blocks a casual glance, not because it protects anything.

Atbash: the mirrored alphabet

Atbash writes the alphabet backwards beneath itself, so A pairs with Z, B with Y, C with X and so on. It comes from the Hebrew alphabet and appears in some ancient texts.

Like ROT13, it has no key at all and undoes itself: mirror the mirror and you are home. That makes it a puzzle, not a lock. Once anyone recognises the pattern, every message ever written with it is open.

Affine cipher: multiply, then shift

Give each letter a number, A = 0 up to Z = 25. The affine cipher takes that number, multiplies by a, adds b, and wraps around at 26:

E(x) = (a·x + b) mod 26

Set a = 1 and you are back to a plain Caesar shift. Multiplying spreads neighbouring letters far apart, which looks more scrambled.

There is a catch. For decryption to work, each ciphertext letter must come from exactly one plaintext letter. That only happens when a shares no common factor with 26. So a = 3 and a = 5 work, but a = 2 or a = 13 do not, because they would send two different letters to the same place. Only 12 values of a are allowed, which with 26 values of b gives 312 keys. Better than 25, but still tiny for a computer.

Keyword substitution: any shuffle at all

Why move every letter by a rule? A substitution cipher lets the key be any shuffled alphabet. To make the shuffle easy to remember, write a keyword first, remove repeated letters, then add the unused letters in order. The keyword ZEBRAS gives the key alphabet ZEBRASCDFGHIJKLMNOPQTUVWXY, so A turns into Z, B into E, C into B, and so on.

The number of possible shuffles is 26 factorial, about 4 × 10²⁶. Trying them all is hopeless, so substitution looked unbreakable for centuries. It was not.

Live lab Live cipher lab. Turn the wheel, encrypt a message and then try to crack it. Open the full Codes & Ciphers Lab lab →

Why none of these are secure today

Substitution ciphers have a fatal habit: a letter always becomes the same letter. So the shape of the language survives. In English, E appears most often, then T, A and O, while Q and Z are rare. Scholars in the Islamic world described frequency analysis around the ninth century: count the letters in the ciphertext, match the commonest to E, and use word patterns (a single-letter word is probably A or I) to fill in the rest.

Longer messages give better statistics, so even a huge key space does not help. Modern ciphers are designed so ciphertext shows no such patterns, and their security rests on keys that are far too large to guess. For anything real, use well-tested modern tools, never your own scheme.

How to explore this in the lab

The Codes & Ciphers Lab gives you a cipher wheel you can turn, plus tools to count letters and test guesses. A good order through the free first world:

  1. Start with The Caesar shift and try breaking one.
  2. See self-inverse behaviour in ROT13, then Atbash.
  3. Test which multipliers work in Affine: multiply, then shift.
  4. Build a shuffled key in Keyword substitution.

This is a simplified teaching model of historical ciphers. It is meant to build intuition about keys and attacks, not to protect real messages.

Key takeaways
  • The key picks the scramble; assume attackers know the method.
  • Caesar has only 25 useful keys, and ROT13 and Atbash have no secret key.
  • The affine multiplier must share no factor with 26, leaving 12 valid values.
  • Keyword substitution has a huge key space but falls to letter-frequency analysis.
Free lesson · Codes & Ciphers Lab

The Caesar shift

Every letter moves the same distance. About 6 minutes. Free, no account, runs in your browser.

Start the free lesson

Report a mistake

What is wrong?
0 / 2000 · at least 10 characters
Sent along with your report
  • Page
  • About Classic Ciphers: Caesar, ROT13, Atbash and Affine · caesar-cipher-rot13-atbash-affine-explained
Plus your browser type. Reports go to our support system; see the privacy notice.

Simulations on Novareka are teaching models, simplified on purpose. They show how an idea behaves; they are not a substitute for professional, medical or engineering advice.