Skip to content
CornerTools

Caesar Cipher

Encode and decode Caesar, ROT13, Atbash and Vigenère, or crack an unknown shift or key automatically.

Characters: 0
Cipher
Direction

Encodes and decodes five classic letter ciphers, and cracks a Caesar shift or a Vigenère key you do not know. Letters keep their case, and spaces stay where they are, so the result keeps the shape of the message; only ROT47 changes digits and punctuation.

  • Caesar moves every letter a fixed number of places along the alphabet, wrapping from Z to A. Suetonius (Life of Julius Caesar, 56) records that Caesar wrote confidential letters with each letter replaced by the one three places on, D for A.
  • ROT13 is Caesar with a shift of 13, half the alphabet, so applying it twice gives back the text. ROT47 does the same over the 94 printable ASCII characters from ! to ~, so digits and punctuation change too.
  • Atbash reverses the alphabet: A becomes Z, B becomes Y. Like ROT13 it undoes itself.
  • Vigenère uses a keyword: each letter of the key gives the shift for one letter of the message, and the key repeats along it, so the same letter is enciphered differently in different places.

How to use it

  • Direction — Encode or Decode, for Caesar and Vigenère; your text stays in the input when you switch. ROT13, ROT47 and Atbash undo themselves, so for them encoding and decoding are the same.
  • Shift — 1 to 25; 3 by default. Shift digits too moves 0–9 by the shift modulo 10, so a shift of 13 turns 1 into 4.
  • Key — letters only, in any case. Key advances on letters only by default, the usual convention, so spaces and punctuation do not use up key letters; Every character moves the key on at each character, as some puzzles do.

Only the unaccented letters A to Z are enciphered. Letters such as é, ß or Devanagari stay as they are, and the tool says so.

In Decode, Caesar lists the message decoded with every shift, and Vigenère looks for the key; clicking a row uses that shift or key. Share sends a link with the cipher and the ciphertext only, which opens in Decode: never the plaintext, the shift or the key.

How it works

Letters are numbered A = 0 to Z = 25. Caesar adds the shift to each letter and wraps past Z; decoding subtracts it. Vigenère does the same with a different shift for each letter, taken from the key in turn (A = 0, B = 1 and so on).

To crack a Caesar shift, the tool decodes with each of the 25 shifts and compares the letter counts of each result with English using Pearson's χ² statistic. The lowest score is marked Most likely; a tie goes to the lower shift. The English letter frequencies are Peter Norvig's counts over the Google Books English corpus, 3.56 trillion letters.

To find a Vigenère key, the tool scores decryptions by how English their letter pairs are, using Norvig's counts of all 676 two-letter sequences from the same corpus. Two letters side by side were enciphered by neighbouring key letters, so for each key length from 1 to 20 (or one per 5 letters, if fewer) the key with the best-scoring decryption can be found exactly, one pair of key letters at a time, instead of guessing each letter alone. Multiples of the true length fit as well as the length itself, and longer keys fit random text a little better, so the shortest length within 0.4 of the best average score per pair is taken. The table shows that key, then the two keys that change one letter at the least cost to the score.

Encode: C = (P + k) mod 26     Decode: P = (C − k) mod 26
χ² = Σ (Oᵢ − Eᵢ)² ÷ Eᵢ, with Eᵢ = N × pᵢ over the letters A–Z
score = Σ log p(xy) over each pair of adjacent letters xy in the decryption

Examples

Encoding with a shift of 3

Plaintext
Attack at dawn!
Ciphertext
Dwwdfn dw gdzq!

Cracking an unknown shift

Ciphertext
Xppe xp mj esp zwo zlv ecpp le xtoytrse
Most likely shift
11
Plaintext
Meet me by the old oak tree at midnight

With 31 letters the counts are enough to rank: the runner-up, shift 4, gives Tlla tl if aol vsk vhr ayll ha tpkupnoa.

Decoding Vigenère with a known key

Ciphertext
Lxfopv ef rnhr
Key
LEMON
Plaintext
Attack at dawn

L minus L is A, X minus E is T, F minus M is T: the key repeats every five letters and skips the spaces.

ROT47 and Atbash

Text
Hello, World! 2026
ROT47
w6==@[ (@C=5P a_ae
Atbash
Svool, Dliow! 2026

The alphabet shifted by 3

Each plain letter and its Caesar cipher with a shift of 3
PlainCipher
AD
BE
CF
DG
EH
FI
GJ
HK
IL
JM
KN
LO
MP
NQ
OR
PS
QT
RU
SV
TW
UX
VY
WZ
XA
YB
ZC

Frequently asked questions

Ranking compares letter counts with English, and a few words rarely have English's mix of letters. On passages of public-domain books, the true shift ranked first in at least 90% of passages from 17 letters, so shorter text is listed in shift order, unranked. A Vigenère key needs more, since each key letter sees only every few letters: the tool looks for one from 46 letters, where it found the right key in 90% of passages with keys of 3 to 8 letters.
No. There are only 25 shifts, so anyone can try them all, as this page does. Vigenère resists that but falls to the statistics above once the message is long. These ciphers suit puzzles, games and teaching; private data needs modern encryption such as AES.

See also