Caesar Cipher Encoder, Decoder and Brute-Force Solver
Shift every letter of a message by a fixed number of places to encrypt it, undo the shift to decrypt it, or try all 25 shifts when the key is unknown.
What is the Caesar cipher?
The Caesar cipher is one of the oldest and simplest substitution ciphers. Each letter of the plaintext is replaced by the letter a fixed number of positions further along the alphabet. The Roman historian Suetonius reports that Julius Caesar used a shift of three to protect military messages, so with a shift of 3 the letter A becomes D, B becomes E, and Z wraps around to C.
Because only 25 non-trivial shifts exist, the cipher offers no real security today. It is still the standard first example in cryptography courses, because it introduces keys, encryption, decryption and modular arithmetic in a form that can be done by hand.
The mathematics: arithmetic modulo 26
Number the letters A = 0, B = 1, …, Z = 25. For a shift k, encryption is E(x) = (x + k) mod 26 and decryption is D(y) = (y − k) mod 26. The remainder after division by 26 is what makes the alphabet wrap around. For example, Y has the number 24, and with k = 3 the sum is 27; since 27 mod 26 = 1, the cipher letter is B.
Decryption is the same operation with the opposite shift, because shifting back by k is the same as shifting forward by 26 − k. ROT13 is the special case k = 13: since 13 + 13 = 26, applying it twice returns the original text, so one function both encrypts and decrypts.
How to break a Caesar cipher
With only 25 possible keys, the simplest attack is brute force: decrypt with every shift and read the results until one makes sense. The brute-force mode of this calculator does exactly that and also ranks the candidates by comparing their letter frequencies with English, where E, T, A, O and N are the most common letters.
The statistical ranking works well for sentences but can fail for very short messages, so always scan the table yourself.
Using this calculator
Choose a mode, type your text and set the shift. The result updates as you type.
- Upper- and lower-case letters keep their case; digits, spaces and punctuation are not changed.
- The step table lists, for each letter, its number x, the sum x + k (or y − k when decrypting), the value mod 26 and the resulting letter.
- Use the brute-force mode to attack a ciphertext whose shift you do not know.
Worked examples
These examples are computed by the same engine as the calculator above, so you can compare each step with your own working.
Encrypt, shift 3
- Mode:
Encrypt - Text:
Hello, World! - Shift k (0–25):
3
Ciphertext
Khoor, Zruog!
shift k = 3 (encryption)
Step-by-step solution
Formula used
E(x) = (x + k) mod 26
A = 0, B = 1, …, Z = 25; k = 3
NoteNumber the letters
A = 0, B = 1, …, Z = 25. Upper- and lower-case letters use the same numbers and keep their case; spaces, digits and punctuation are copied unchanged.
Shift k = 3, 10 letters to convert.
NoteAlphabet mapping (plain → cipher)
Plain letter : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher letter: DEFGHIJKLMNOPQRSTUVWXYZABC
CalculateConvert every letter
x → (x + 3) mod 26
| # | Letter | x | x + k | mod 26 | Result |
|---|
| 1 | H | 7 | 10 | 10 | K |
| 2 | e | 4 | 7 | 7 | h |
| 3 | l | 11 | 14 | 14 | o |
| 4 | l | 11 | 14 | 14 | o |
| 5 | o | 14 | 17 | 17 | r |
| 6 | W | 22 | 25 | 25 | Z |
| 7 | o | 14 | 17 | 17 | r |
| 8 | r | 17 | 20 | 20 | u |
| 9 | l | 11 | 14 | 14 | o |
| 10 | d | 3 | 6 | 6 | g |
CheckVerify by reversing
Decrypting the result with the same shift gives back the original text: ✓ yes
ResultCiphertext
Khoor, Zruog!
Decrypt ROT13
- Mode:
Decrypt (known shift) - Text:
URYYB JBEYQ - Shift k (0–25):
13
Plaintext
HELLO WORLD
shift k = 13 (decryption)
Shift 13 is ROT13: applying it twice returns the original text, so encryption and decryption are the same operation.
Step-by-step solution
Formula used
D(y) = (y − k) mod 26
A = 0, B = 1, …, Z = 25; k = 13
NoteNumber the letters
A = 0, B = 1, …, Z = 25. Upper- and lower-case letters use the same numbers and keep their case; spaces, digits and punctuation are copied unchanged.
Shift k = 13, 10 letters to convert.
NoteAlphabet mapping (cipher → plain)
Cipher letter: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Plain letter : NOPQRSTUVWXYZABCDEFGHIJKLM
CalculateConvert every letter
y → (y − 13) mod 26
| # | Letter | y | y − k | mod 26 | Result |
|---|
| 1 | U | 20 | 7 | 7 | H |
| 2 | R | 17 | 4 | 4 | E |
| 3 | Y | 24 | 11 | 11 | L |
| 4 | Y | 24 | 11 | 11 | L |
| 5 | B | 1 | -12 | 14 | O |
| 6 | J | 9 | -4 | 22 | W |
| 7 | B | 1 | -12 | 14 | O |
| 8 | E | 4 | -9 | 17 | R |
| 9 | Y | 24 | 11 | 11 | L |
| 10 | Q | 16 | 3 | 3 | D |
CheckVerify by reversing
Encrypting the result with the same shift gives back the original text: ✓ yes
ResultPlaintext
HELLO WORLD
Brute force
- Mode:
Brute force (unknown shift) - Text:
WKLV LV D VHFUHW PHVVDJH
Most likely plaintext
THIS IS A SECRET MESSAGE
shift k = 3 (guess from English letter frequencies)
The best guess is chosen by comparing letter frequencies with English (chi-squared test). Always read the candidates yourself: the guess is only a hint.
Step-by-step solution
Formula used
D(y) = (y − k) mod 26 for every k = 1, 2, …, 25
A = 0, B = 1, …, Z = 25
NoteWhy brute force works
A Caesar cipher has only 25 non-trivial keys (k = 0 leaves the text unchanged).
So we simply try every shift and look for the one that gives readable text.
CalculateDecrypt with every shift k = 1 … 25
candidate(k) = D(ciphertext) with D(y) = (y − k) mod 26
| Shift k | Candidate plaintext | Chi-squared | Guess |
|---|
| 1 | VJKU KU C UGETGV OGUUCIG | 153.6 | |
| 2 | UIJT JT B TFDSFU NFTTBHF | 185.3 | |
| 3 | THIS IS A SECRET MESSAGE | 21.6 | ◀ best guess |
| 4 | SGHR HR Z RDBQDS LDRRZFD | 358.4 | |
| 5 | RFGQ GQ Y QCAPCR KCQQYEC | 1360.3 | |
| 6 | QEFP FP X PBZOBQ JBPPXDB | 553.7 | |
| 7 | PDEO EO W OAYNAP IAOOWCA | 33.8 | |
| 8 | OCDN DN V NZXMZO HZNNVBZ | 1148.8 | |
| 9 | NBCM CM U MYWLYN GYMMUAY | 99.7 | |
| 10 | MABL BL T LXVKXM FXLLTZX | 650.3 | |
| 11 | LZAK AK S KWUJWL EWKKSYW | 291.4 | |
| 12 | KYZJ ZJ R JVTIVK DVJJRXV | 1216.6 | |
| 13 | JXYI YI Q IUSHUJ CUIIQWU | 417.2 | |
| 14 | IWXH XH P HTRGTI BTHHPVT | 169.8 | |
| 15 | HVWG WG O GSQFSH ASGGOUS | 131.5 | |
| 16 | GUVF VF N FRPERG ZRFFNTR | 155.7 | |
| 17 | FTUE UE M EQODQF YQEEMSQ | 862.2 | |
| 18 | ESTD TD L DPNCPE XPDDLRP | 97.1 | |
| 19 | DRSC SC K COMBOD WOCCKQO | 130.4 | |
| 20 | CQRB RB J BNLANC VNBBJPN | 279.1 | |
| 21 | BPQA QA I AMKZMB UMAAIOM | 334.5 | |
| 22 | AOPZ PZ H ZLJYLA TLZZHNL | 1742.3 | |
| 23 | ZNOY OY G YKIXKZ SKYYGMK | 467.5 | |
| 24 | YMNX NX F XJHWJY RJXXFLJ | 1365.4 | |
| 25 | XLMW MW E WIGVIX QIWWEKI | 255.6 | |
ResultPick the readable candidate
Most likely: shift 3 → THIS IS A SECRET MESSAGE
Frequently asked questions
What shift did Julius Caesar use?
According to Suetonius, Caesar shifted each letter by three places, so A became D. Other Roman sources mention a shift of four used by Augustus.
Is the Caesar cipher secure?
No. There are only 25 usable keys, so an attacker can try them all in seconds, and letter-frequency analysis breaks it even without trying every key. It is useful for learning, not for protecting real data.
What happens to spaces, digits and punctuation?
They are left unchanged. Only the 26 letters A to Z are shifted, and each letter keeps its upper or lower case.
How do I decrypt a Caesar cipher when I do not know the shift?
Switch to the brute-force mode. It decrypts the text with all 25 shifts and highlights the candidate whose letter frequencies look most like English.
What is ROT13?
ROT13 is the Caesar cipher with a shift of 13. Because the alphabet has 26 letters, applying ROT13 twice gives back the original text.