Computer Science › Tools › Caesar cipher wheel
Caesar cipher wheel
Encode and decode messages with the Caesar cipher. Type plaintext or ciphertext, choose a shift, and watch the wheel change each letter in turn. Turn the inner wheel by dragging it, clicking a letter or using the arrow keys.
Outer ring: plaintextInner ring: ciphertext
Crack a Caesar cipher: try every shift
There are only 25 useful shifts, so a computer can try every one in a moment. This is called a brute-force attack. The table decrypts the ciphertext above with every shift and marks the one whose letters look most like English (it compares letter frequencies).
What is the Caesar cipher?
The Caesar cipher (sometimes spelt Caesar cypher) is one of the oldest and simplest ways to encrypt a message. Each letter is replaced by the letter a fixed number of places further along the alphabet. That number is the shift, and it is the key. With a shift of 3, A becomes D, B becomes E and Z wraps round to C. It is named after Julius Caesar, who is said to have used a shift of 3 in his private letters.
It is a substitution cipher and a symmetric one: the same key encrypts and decrypts. To decrypt, shift the same number of places backwards.
How to use a Caesar cipher wheel
- Turn the inner wheel until the letter A on the outer ring sits over the letter your shift points to (for a shift of 3, the inner D).
- To encrypt, find each plaintext letter on the outer ring and write down the letter beneath it on the inner ring.
- To decrypt, find each ciphertext letter on the inner ring and write down the letter above it on the outer ring.
- Leave spaces, digits and punctuation as they are.
Worked example
Encrypt ATTACK AT DAWN with a shift of 3:
| Plaintext | A | T | T | A | C | K | A | T | D | A | W | N | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Ciphertext | D | W | W | D | F | N | D | W | G | D | Z | Q |
So the ciphertext is DWWDFN DW GDZQ.
The Caesar cipher formula
Number the letters A = 0, B = 1, … Z = 25. For a letter x and a shift n:
Encrypt: E(x) = (x + n) mod 26
Decrypt: D(x) = (x − n) mod 26
“mod 26” means “take the remainder after dividing by 26”, which is what makes Z wrap round to the start of the alphabet.
Caesar cipher in Python
A short program that encrypts with a positive shift and decrypts with a negative one. It uses ord() to turn a letter into its character code and chr() to turn it back.
def caesar(text, shift):
result = ""
for ch in text:
if ch.isupper():
result += chr((ord(ch) - 65 + shift) % 26 + 65)
elif ch.islower():
result += chr((ord(ch) - 97 + shift) % 26 + 97)
else:
result += ch # spaces and punctuation stay the same
return result
print(caesar("Hello, World!", 3)) # Khoor, Zruog!
print(caesar("Khoor, Zruog!", -3)) # Hello, World!
Why the Caesar cipher is not secure
- Brute force: there are only 25 possible keys, so trying them all takes seconds by hand and no time at all by computer.
- Frequency analysis: each letter always turns into the same letter, so the most common ciphertext letter is probably E, the most common letter in English.
- The Vigenère cipher fixes the first two problems by using a keyword, so each letter gets its own shift.
- Modern systems use encryption such as AES (symmetric) and RSA (asymmetric), with keys so large that trying every one is impossible.
ROT13
ROT13 is the Caesar cipher with a shift of 13. Because 13 is half of 26, doing it twice gets you back where you started, so the same step encrypts and decrypts. It is used online to hide spoilers and puzzle answers, not to keep secrets. Press ROT13 above to try it.
Where it appears in the curriculum
The Caesar cipher is a common starting point for encryption in KS3 Computing, GCSE (AQA 8525 cyber security, OCR J277 network security), Cambridge IGCSE 0478 (data transmission: symmetric and asymmetric encryption) and Edexcel International GCSE. It is also a classic programming task for practising loops, strings and character codes. On TermStep it is taught in KS3 Year 9 Cybersecurity and used again in the IGCSE 0478 and GCSE courses.
Questions and answers
How do you decode a Caesar cipher without the key?
Try every shift from 1 to 25 and look for the one that gives readable English (a brute-force attack), or count the letters and guess that the most common one stands for E (frequency analysis). The “Try all 25 shifts” button on this page does the first for you.
What shift did Julius Caesar use?
According to the Roman historian Suetonius, Caesar used a shift of 3, so A was written as D.
Is the Caesar cipher symmetric or asymmetric?
Symmetric: the same key (the shift) is used to encrypt and to decrypt. Asymmetric encryption uses a pair of keys, one public and one private.
What happens with a shift of 26?
Nothing changes, because shifting 26 places takes every letter all the way round the alphabet back to itself. A shift of 27 is the same as a shift of 1.
Does the Caesar cipher change numbers and punctuation?
No. The classic Caesar cipher only shifts letters. Spaces, digits and punctuation are copied across unchanged, and capital letters stay capital.
Is Caesar cipher spelt “cipher” or “cypher”?
Both spellings are used. “Cipher” is the more common spelling today and is the one used by exam boards.