Skip to content
CryptographyInternals

Caesar cipher

Shift every letter a fixed number of places down the alphabet.

Family
Monoalphabetic substitution
Era
1st century BC
Keys
25 useful keys

Suetonius records that Julius Caesar protected his military letters by replacing each letter with the one three places further down the alphabet. Any fixed shift works the same way, and the shift is the whole key.

Turn the inner ring of the wheel below to choose a shift, then step through your message to watch each letter move.

Message
A
T
T
A
C
K
A
T
D
A
W
N
In detail
A0B1C2…Z25

A = 0 … Z = 25

01 / 12 · Inside the Caesar cipher

A message to hide

This readable text is the plaintext. Encrypting turns it into ciphertext, which should mean nothing to anyone without the key. Classical ciphers only touch letters.

Everything that follows has one goal: whoever intercepts the ciphertext must not be able to get back to these letters.

Playground

Shift your own message

Type a message, pick a shift and step through it letter by letter. The panel on the right does the arithmetic on each of your letters.

Your input

+3
Result
Input
Output

Encrypt

Shift every letter by 3

What happens

Number the letters A = 0 … Z = 25. Encrypting adds 3 to each letter’s number, decrypting subtracts it. The two rings of the wheel show the result for all 26 letters at once.

On your values

E(x) = (x + 3) mod 26

A→D B→E Z→C

Why it matters

The key is one number between 1 and 25. That tiny keyspace (the set of all possible keys) is the cipher’s weakness: see how it’s broken below.

Spaces, digits and punctuation pass through unchanged; accents are dropped.

The basics: Modular arithmetic →

Start

How it’s broken

Try all 25 shifts, keep the one that reads

An attacker does not need the key: they shift the ciphertext back by every possible amount. Each candidate is scored by how typical its letters are in English (sum of the logarithm of each letter’s frequency); the highest score is almost always the message.

Attacking the ciphertext: Dwwdfn dw gdzq

  1. −1Cvvcem cv fcyp
  2. −2Buubdl bu ebxo
  3. −3Attack at dawn
  4. −4Zsszbj zs czvm
  5. −5Yrryai yr byul
  6. −6Xqqxzh xq axtk
  7. −7Wppwyg wp zwsj
  8. −8Voovxf vo yvri
  9. −9Unnuwe un xuqh
  10. −10Tmmtvd tm wtpg
  11. −11Sllsuc sl vsof
  12. −12Rkkrtb rk urne
  13. −13Qjjqsa qj tqmd
  14. −14Piiprz pi splc
  15. −15Ohhoqy oh rokb
  16. −16Nggnpx ng qnja
  17. −17Mffmow mf pmiz
  18. −18Leelnv le olhy
  19. −19Kddkmu kd nkgx
  20. −20Jccjlt jc mjfw
  21. −21Ibbiks ib liev
  22. −22Haahjr ha khdu
  23. −23Gzzgiq gz jgct
  24. −24Fyyfhp fy ifbs
  25. −25Exxego ex hear

−3 = best score

A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
your ciphertextEnglish letters

Shortcut: your ciphertext’s most common letter is D (3). If it stands for E (4), the shift is 3 − 4 + 26 = 25.

Short texts can fool the statistics: the longer the ciphertext, the surer the attack. Try the long-text preset.

How it works

  1. 1Pick a shift k between 1 and 25.
  2. 2For each letter, count k places forward in the alphabet, wrapping from Z back to A.
  3. 3Leave spaces, digits and punctuation as they are.
  4. 4To decrypt, count k places backward instead.

Formula

E(x) = (x + k) mod 26
D(x) = (x − k) mod 26

How it is broken

There are only 25 possible keys, so an attacker can try them all by hand in a few minutes.

Every letter is always replaced by the same letter, so the frequency pattern of the language survives: the most common ciphertext letter usually stands for E.

Read the in-depth articleHow to Crack a Caesar Cipher and Break VigenèreA hands-on cryptanalysis tutorial: crack a Caesar cipher by brute force and frequency analysis, then break Vigenère with Kasiski to recover the key LEMON.