Skip to content

Caesar Cipher – Encoder and Decoder

Updated:

Encode or decode a Caesar cipher online: enter your text, choose a direction and shift key k (Caesar's classic k = 3), and get the shifted message, the full alphabet mapping and a brute-force table that ranks every possible key.

Shift a Message Like Caesar — or Crack One

Input Fields
k
Caesar's own key. 0–25 is usual; negative values shift the other way (−3 ≡ +23 on A–Z), and any whole number wraps automatically.
If enabled, the result will update automatically when you change any value.

Caesar Cipher Formula

Formula
\[ C = (P + k) \bmod 26 \qquad\qquad P = (C - k) \bmod 26 \]

Where:

  • \(P\) — position of the plaintext letter in the alphabet (A = 0, B = 1, …, Z = 25)
  • \(C\) — position of the ciphertext letter
  • \(k\) — the shift key; Caesar himself used \(k = 3\)
  • \(\bmod\ 26\) — the remainder after division by 26, which makes the alphabet wrap around: after Z comes A again

The first line encodes (each letter moves \(k\) places forward), the second decodes (each letter moves \(k\) places back). For a custom alphabet of length \(N\), simply replace 26 with \(N\) and the same wrap-around logic applies.

Caesar Cipher – Calculation Example

Example: encode the message “Meet me behind the old wall at midnight” with Caesar's classic key \(k = 3\).

\[ P = 12 \;(\text{M}),\quad C = (12 + 3) \bmod 26 = 15 \implies \text{M} \to \text{P} \]

\[ P = 4 \;(\text{e}),\quad C = (4 + 3) \bmod 26 = 7 \implies \text{e} \to \text{h} \]

Letters near the end of the alphabet wrap around: X (23) → A, Y (24) → B, Z (25) → C.

Result: Phhw ph ehklqg wkh rog zdoo dw plgqljkw

Check: decoding that text with the same key \(k = 3\) brings back the original message, because encoding and decoding are exact inverses of each other.

How to use the calculator

  1. Pick the Direction: “Encode — shift letters forward” to hide a message, or “Decode — shift letters back” to reveal one whose key you already know.
  2. Set the Shift (k) — the secret key. Try 3 for Caesar's original cipher or 13 for ROT13. Any whole number from −25 to 25 works; it wraps automatically.
  3. Type or paste your message into Your text. Both uppercase and lowercase letters are shifted.
  4. Decide whether to tick Keep case (ATTACK stays ATTACK) or leave it off for lowercase output, the classic cryptogram style.
  5. Choose what to do under Non-letters: keep spaces, digits and punctuation so the result stays readable, or drop them for a pure letters-only ciphertext.
  6. Under Alphabet, stay with English A–Z or switch to Custom alphabet and enter your own set of unique characters. For encoding, read the Shifted text result; for cracking a message with an unknown key, scan the brute-force table and pick the shift whose candidate actually reads like English.
  7. Use the Copy button to transfer the result straight to your clipboard.

What is the Caesar cipher?

The Caesar cipher is one of the oldest and simplest encryption methods in existence: every letter of a message is replaced by the letter standing \(k\) places further along the alphabet, with the alphabet wrapping from Z back to A. With \(k = 3\), A becomes D, B becomes E, and “X Y Z” wraps to “A B C”.

It is named after Julius Caesar, who, according to the historian Suetonius, used exactly this shift of three to protect military correspondence during his campaigns in Gaul (58–50 BC). His successor Augustus reportedly preferred the more modest shift of one. For its time the cipher was effective; today it is a teaching classic — the perfect first step into modular arithmetic and substitution ciphers, and the ancestor of far stronger systems.

A famous special case is ROT13: because \(13 + 13 = 26\), a shift of 13 is its own inverse. Encoding a text twice with ROT13 returns the original, which made it a popular way to hide spoilers and puzzle answers in early internet forums. If you need a different text-encoding scheme for practical use, try the Base64 encoder or the Morse code converter.

Beyond the shifted output, the calculator shows two extras that make the cipher transparent. The shifted alphabet strip draws the complete letter mapping (every A→D pair), and the brute-force table tries all remaining 25 shifts at once. Each candidate is scored with the chi-squared (χ²) statistic against typical English letter frequencies — English is unusually rich in e (≈12.7%), t (≈9.1%) and a (≈8.2%) — so the candidate that reads most like English almost always lands first in the ranking. That is also how real codebreakers attack such ciphers, a technique documented as early as the 9th century by the Arab scholar Al-Kindi.

Assumptions, limitations and tips

  • Choose the same key, opposite direction. Whatever key encoded the message (e.g. k = 3 forward) is exactly the key that decodes it (k = 3 backward). A negative key and its positive complement are equivalent: −3 behaves like +23 on a 26-letter alphabet.
  • Short texts weaken the ranking. The χ² frequency analysis needs roughly 30+ English letters to be reliable. For very short or unusual messages, trust your eyes instead: read the brute-force table yourself and pick the line that makes sense.
  • Case and non-letters must match. The output depends on the “Keep case” and “Non-letters” options, so set them the same way when you encode and when you decode, otherwise the recovered text will differ in formatting.
  • Never use it for real secrets. With at most 25 meaningful keys, a Caesar cipher is broken in seconds by brute force or frequency analysis. For genuine protection use the password generator with long random keys and modern cryptographic tools.
  • Custom alphabets shift by position, not by ASCII code. Only characters present in your alphabet string move; duplicates and spaces are ignored, and shifting wraps within the string just like A–Z within 26.
  • Useful keys to try: k = 3 for the historical cipher, k = 13 for ROT13, k = 1 for Augustus, and any key between 1 and 25 for classroom cipher games and treasure hunts.

Frequently Asked Questions

How do I decode a Caesar cipher without knowing the shift key?

Try all 25 possible shifts — that is exactly what the brute-force table does for you. Because a Caesar cipher has at most 25 meaningful keys, you can decode the message with each one and pick the result that reads like real English. For a faster manual method, count the most frequent letter in the ciphertext: in English it usually corresponds to "e", which often reveals the shift immediately.

Why is ROT13 its own inverse?

The alphabet has 26 letters, and a shift of 13 is exactly half of that. Encoding adds 13, so encoding twice adds 26, which lands you back on the starting letter: \(13 + 13 \equiv 0 \pmod{26}\). This means the same tool setting both scrambles and reveals a message — you never need a separate decode mode for ROT13.

What shift values did Caesar and Augustus actually use?

According to the historian Suetonius, Julius Caesar used a shift of 3 (A→D) for military correspondence during his Gallic campaigns, which is why k = 3 is the classic default. His successor Augustus reportedly used a shift of just 1 (A→B). Both are trivially breakable today but were reasonably secure when literacy was rare.

Can I use a Caesar cipher for the Russian or another alphabet?

Yes. Any alphabet works because the cipher shifts by position within the alphabet, not by ASCII code. Select "Custom alphabet" and type the full character set, for example the 33 Cyrillic letters А–Я (with Ё). The shift wraps around that alphabet's own length N instead of 26, and letters not in your list pass through unchanged.

Does the Caesar cipher keep spaces and punctuation?

That is up to you. The calculator offers two modes: keep spaces, digits and punctuation for readable output, or drop everything except letters for the traditional letters-only ciphertext. Historically, ciphers usually removed spaces to hide word boundaries — a message like QZSDOGPQ is harder to attack than QZS DOG PQ, because word patterns give clues to a codebreaker.

Why does my decoded text look like gibberish even with the right key?

Check that your encoding and decoding settings match exactly. If the message was encoded with non-letters dropped but you decode with them kept (or vice versa), the text differs in formatting. Also verify the alphabet: a text encoded on a custom alphabet decodes correctly only on that same alphabet. Finally, try the key's negative complement — if encoding used k = 3, decoding needs a shift of 3 backward, which equals 23 forward.

How is the Caesar cipher different from the Vigenère cipher?

The Caesar cipher uses one fixed shift for every letter; the Vigenère cipher uses a repeating keyword, so each letter is shifted by a different amount depending on its position. Vigenère was historically called "le chiffre indéchiffrable" because a single-letter frequency count cannot break it — but once you know the keyword length, it splits into several Caesar ciphers that can each be attacked separately.

Leave a Reply

Your email address will not be published. Required fields are marked *