Classic ciphers for beginners: Caesar, Atbash, Vigenère and more
Long before computers, people hid messages with simple rules. These classic ciphers are fun puzzles and a gentle way into how encryption works. None of them is secure today, but each shows a different idea.
Two families of ciphers
Substitution ciphers replace each letter with another letter or symbol. Transposition ciphers keep the letters but change their order. Many classic ciphers belong to one of these two families.
Caesar cipher: shift the alphabet
Shift every letter along the alphabet by a fixed number. With a shift of 3, A becomes D, B becomes E and Z wraps round to C. Julius Caesar is said to have used a shift of 3, so HELLO becomes KHOOR. There are only 25 useful shifts, so it can be broken by trying all of them.
Atbash: reverse the alphabet
Atbash swaps the first letter with the last, the second with the second to last, and so on, so A becomes Z and B becomes Y. HELLO becomes SVOOL. It has no key at all, and applying it twice gives back the original text.
Vigenère: a different shift for each letter
Vigenère uses a keyword. Each letter of the message is shifted by the matching letter of the keyword, repeated as needed, where A means a shift of 0, B a shift of 1 and so on. With the key LEMON, the message ATTACKATDAWN becomes LXFOPVEFRNHR. For centuries it was called unbreakable, until methods were found to work out the key length.
Affine: multiply and add
The affine cipher turns each letter into a number from 0 to 25, multiplies it by a, adds b and takes the remainder after dividing by 26. The value of a must share no factor with 26, which leaves 12 valid choices, so that the process can be reversed. With a = 5 and b = 8, AFFINE CIPHER becomes IHHWVC SWFRCP.
Rail fence: write in a zigzag
The rail fence cipher is a transposition. Write the message in a zigzag across a number of rows, the rails, then read each row in turn. With 3 rails, WEAREDISCOVEREDFLEEATONCE becomes WECRLTEERDSOEEFEAOCAIVDEN.
Polybius square: letters become numbers
Write the alphabet in a 5 by 5 grid, with I and J sharing a cell. Each letter is replaced by its row and column number, so HELLO becomes 23 15 31 31 34. A keyword placed at the start of the grid changes the layout.
Bacon cipher: five symbols per letter
Francis Bacon replaced each letter with a group of five symbols, A or B, which is really a five-digit binary number. HELLO becomes AABBB AABAA ABABB ABABB ABBBA. Bacon intended the A and B to be hidden in two slightly different typefaces, so the message looked ordinary.
Why none of them is secure
- Frequency analysis: in English, E is the commonest letter, and substitution ciphers keep that pattern.
- Small key spaces: Caesar, Atbash and the affine cipher have very few possible keys, so a computer tries all of them instantly.
- Real security today uses modern algorithms such as AES, with keys too large to search.
Try them
Each cipher above has a free encoder and decoder on Toolstia: the Caesar, Atbash, Vigenère, affine, rail fence, Polybius and Bacon tools. They are great for puzzles, escape rooms and teaching, and they run in your browser.