3tej home
← All Games

What is Caesar Cipher?

A Caesar Cipher computes caesar cipher from the inputs you provide. It applies the standard formula to the values you enter and returns the result instantly, without sending any data to a server. Shift letters by N positions. The tool.

Caesar Cipher

Shift letters by N. Encode and decode.

About the Caesar cipher

The Caesar cipher is a monoalphabetic substitution cipher that shifts every letter of the plaintext N positions along the alphabet, wrapping Z back to A. The Roman historian Suetonius records that Julius Caesar used a shift of 3 to encode private letters to Cicero around 50 BC, replacing each Latin letter with the one three positions later. Augustus is reported to have used a shift of 1.

Today the Caesar cipher has no security value: with only 25 distinct keys, a modern computer brute-forces every shift in microseconds. Its lasting role is pedagogical. It introduces students of cryptography to the core ideas of plaintext, ciphertext, key, modular arithmetic, brute-force attack, and frequency analysis without any heavyweight mathematics. It also shows up in puzzle hunts, escape rooms, geocache challenges, and the famous ROT13 convention used on Usenet and Reddit to hide spoilers.

How it works

Each letter is treated as a number 0 to 25 (A = 0, B = 1, ..., Z = 25). Encryption adds the shift N modulo 26; decryption subtracts N modulo 26. Non-alphabetic characters (digits, spaces, punctuation) pass through unchanged. Case is preserved.

encrypt(letter)  = (letter + shift) mod 26
decrypt(letter)  = (letter - shift + 26) mod 26
shift range      = 0 to 25 (shift 0 = identity, shift 26 = identity)
ROT13            = encrypt with shift 13 (self-inverse)
  • Shift: integer 1 to 25.
  • Symmetric: encrypt(decrypt(x)) = x for the same shift.
  • Brute-force surface: only 25 possible keys; trivially broken.

Worked example

Encrypt "HELLO" with shift 3 (Caesar's original).

  1. Map letters to numbers: H=7, E=4, L=11, L=11, O=14.
  2. Add 3 mod 26: 10, 7, 14, 14, 17.
  3. Map back: K, H, O, O, R.
  4. Output: KHOOR.
  5. Decrypt: subtract 3 mod 26 returns HELLO.
Result: "HELLO" with shift 3 encrypts to "KHOOR". Brute-force trying shifts 1 through 25 yields readable English at shift 3, so an attacker breaks this in at most 25 attempts. Real-world classical use required either a courier or a daily key change.

Alphabet to number map (shift table)

LetterNumberLetterNumber
A0N13
B1O14
C2P15
D3Q16
E4R17
F5S18
G6T19
H7U20
I8V21
J9W22
K10X23
L11Y24
M12Z25

To encrypt: letter number plus shift, mod 26. To decrypt: letter number minus shift, mod 26.

Breaking the cipher: frequency analysis

Brute force is the textbook attack but frequency analysis is faster and works on any length of ciphertext above about 50 characters. Every natural language has a stable letter-frequency profile. In English, E appears about 12.7 percent of the time, T about 9.1 percent, A about 8.2 percent. After encryption with shift N, those frequencies do not change, they just slide N positions along the alphabet.

RankEnglish letterFrequencyIf shifted by 3, appears as
1E12.7%H
2T9.1%W
3A8.2%D
4O7.5%R
5I7.0%L
6N6.7%Q
7S6.3%V
8H6.1%K

If the most common letter in your ciphertext is H, the shift is almost certainly 3 (E to H). Cross-check with the second most common.

Common pitfalls

  • Not secure for any modern purpose. Only 25 keys means a brute-force attack finishes in milliseconds. Use AES, ChaCha20, or RSA for any real confidentiality need.
  • Frequency analysis breaks it faster than brute force. The most common letter in English ciphertext almost always maps to E. One peek at letter counts reveals the shift.
  • Off-by-one shift confusion. A "shift of 3" can mean either A becomes D (+3) or A becomes the third letter, which is C (+2). The tool uses A becomes D, the standard convention.
  • Case and punctuation. Most implementations preserve case (uppercase stays uppercase) and pass digits, spaces, and punctuation unchanged. Strict variants strip everything but letters.
  • Shift 13 (ROT13) is self-inverse. Applying ROT13 twice returns the original. It is the only shift with this property because 13 + 13 = 26.
  • Multilingual text. The classical Caesar applies only to a 26-letter alphabet. Extended alphabets (accented Latin, Cyrillic, Greek) need their own modulus.
  • Short messages defeat frequency analysis. A 4-letter ciphertext gives almost no statistical signal, which is why short Caesar puzzles are still solvable only by brute force.

Caesar variants worth knowing

VariantKey ideaKey spaceStill solvable?
Caesar (shift)Single fixed shift N25 keysTrivial brute force
ROT13Caesar with shift 131 keyNo effort, self-inverse
AtbashA to Z, B to Y, mirror1 keyTrivial pattern
Affine(a x + b) mod 26312 keysFrequency analysis
VigenereCaesar with rotating key word26^len(key)Kasiski 1863, Friedman 1925
SubstitutionArbitrary letter mapping26! keysFrequency + n-grams

Vigenere held the title of "le chiffre indechiffrable" for 300 years because its key space looks astronomical, but Kasiski showed in 1863 that key length leaks from repeated ciphertext fragments. Once length is known, Vigenere reduces to a stack of independent Caesar ciphers.

Related tools and glossary

Frequently asked questions

What is the Caesar cipher?

The Caesar cipher is a substitution cipher named after Julius Caesar, who used a shift of 3 to encode military messages around 50 BC. Each letter in the plaintext is shifted N positions down the alphabet; A becomes D with a shift of 3, B becomes E, and so on, wrapping from Z back to A. It is one of the simplest classical ciphers.

What is ROT13?

ROT13 is a Caesar cipher with a shift of 13. Because the English alphabet has 26 letters, applying ROT13 twice returns the original text, which makes it self-inverse. It is widely used on the internet to hide minor spoilers, punchlines, and joke answers without security intent.

Is the Caesar cipher secure?

No. There are only 25 possible shifts (a shift of 0 leaves text unchanged), so a brute-force attack tries every shift in well under a second. Frequency analysis cracks it even faster by identifying the most common letter and assuming it maps to E. Use it for puzzles and teaching, not security.

How do I decrypt a Caesar cipher?

Apply the inverse shift. If the text was encrypted with shift 3 (A becomes D), decrypt by shifting back 3 positions or, equivalently, forward by 26 minus 3 = 23. The tool decrypts by negating the shift value automatically.

Sources

  • Suetonius, Lives of the Twelve Caesars, on Julius Caesar's encrypted correspondence.
  • David Kahn, The Codebreakers (Scribner, 1996), classical cryptography survey.
  • Bruce Schneier, Applied Cryptography, 2nd ed., on substitution ciphers.

Last updated 2026-05-28.