What the Caesar cipher is
The Caesar cipher is a monoalphabetic substitution in which each letter is replaced by another letter a fixed number of positions away. With shift three, A becomes D, B becomes E, and X, Y, Z wrap around to A, B, C. Decoding moves in the opposite direction by the same shift. The method is named after Julius Caesar’s reported use of letter shifting for military correspondence.
This implementation defines the alphabet precisely as the twenty-six ASCII English letters A-Z and a-z. Case is preserved, and characters outside those ranges—including digits, spaces, punctuation, accented letters, CJK characters, and emoji—are copied unchanged. A shift may be any whole integer; it is normalized modulo twenty-six, so 29 behaves like 3 and -1 behaves like 25 for encoding.
The Caesar cipher is not secure encryption. There are only twenty-six possible shifts, including the identity shift, and language patterns remain visible. A person or trivial program can try every shift immediately. Use this page for education, puzzles, historical examples, and compatibility testing, never for passwords, private messages, tokens, personal data, or any situation requiring confidentiality.
How to encode or decode a Caesar shift
- Choose Encode to move letters forward or Decode to move them backward.
- Enter a whole-number shift. Values outside 0-25 are normalized modulo 26, which makes negative and large values predictable.
- Type or paste the text. The result updates while preserving letter case and every non-ASCII or non-letter character.
- Use the ROT13 shortcut to set shift 13. ROT13 uses the same operation for encoding and decoding because it is self-inverse.
- If the shift is unknown, test all twenty-six possibilities and judge the readable result; this tool does not pretend that brute-force recovery is cryptanalysis-grade security.
Caesar shift and ROT13 examples
The examples cover wraparound, case preservation, negative-equivalent shifts, non-English text, decode direction, and ROT13’s self-inverse behavior.
Classic shift 3
Input: Attack at Dawn!
Output: Dwwdfn dw Gdzq!
Uppercase and lowercase letters shift independently, while spaces and punctuation remain unchanged.
Decode shift 3
Input: Dwwdfn dw Gdzq!
Output: Attack at Dawn!
Decode subtracts the normalized shift instead of requiring a separate negative number.
Alphabet wraparound
Input: xyz XYZ
Output: abc ABC
Letters past z or Z wrap to the beginning of the same alphabet.
ROT13
Input: Hello, World!
Output: Uryyb, Jbeyq!
A shift of thirteen is its own inverse because applying it twice advances by twenty-six positions.
Large shift normalization
Input: abc
Output: def
A shift of 29 is normalized modulo 26 and behaves exactly like shift 3.
Preserved nonletters
Input: Hello, 世界! 123
Output: Khoor, 世界! 123
This implementation shifts only ASCII A-Z and a-z; all other characters pass through unchanged.
Shift range and character behavior
The shift control accepts finite integers. Internally the value is reduced with a positive modulo operation, producing a number from zero through twenty-five. Decode applies the complementary movement, so decode shift three is equivalent to encode shift twenty-three.
Only code points for ASCII A-Z and a-z are transformed. This narrow rule avoids claiming a universal alphabet for every language. Extending Caesar-style rotation to accented or non-Latin scripts requires an explicitly ordered alphabet and language-specific decisions.
- Shift 0 and every multiple of 26 return the original text.
- Shift 13 is ROT13 and applying it twice restores the input.
- Uppercase letters remain uppercase and lowercase letters remain lowercase.
- Spaces, punctuation, digits, emoji, and non-Latin scripts are preserved exactly.
- Fractional, infinite, or non-numeric shifts are invalid.
How modulo-26 letter rotation works
Each ASCII letter is converted to a zero-based alphabet index. For uppercase A is zero and Z is twenty-five; lowercase uses the same indexes with a different character-code offset. Encoding adds the normalized shift, takes the result modulo twenty-six, and converts the index back to a character.
Decoding can subtract the shift directly or add its complement, 26 minus the normalized shift. Using the complement keeps every intermediate value non-negative. Wraparound is therefore a property of modular arithmetic rather than a list of special cases for X, Y, and Z.
The function processes Unicode code points but transforms only one-unit ASCII letters. Other characters are returned unchanged. There is no key schedule, randomness, initialization vector, block mode, authentication tag, or secret state. The entire keyspace is the visible shift value.
Appropriate uses for a Caesar cipher
The cipher remains useful because it demonstrates substitution and modular arithmetic with almost no machinery. Its weakness is part of the lesson.
Classroom exercises
Show letter indexes, modular wraparound, frequency analysis, and the difference between encoding, encryption, and secure cryptography.
Puzzles and escape games
Create hints that are intentionally recoverable by trying a small number of shifts.
ROT13 community conventions
Obscure spoilers or punchlines in contexts where everyone understands that the text is not protected.
Programming practice
Test string iteration, character classes, case preservation, negative modulo behavior, and reversible transformations.
Historical demonstrations
Illustrate why a once-practical manual method is inadequate against modern computation and statistical analysis.
Caesar cipher limitations and mistakes
The most serious mistake is treating the result as confidential. Trying every possible shift takes negligible time, and ordinary-language scoring can identify the likely plaintext automatically. Even without brute force, repeated letters, word lengths, and punctuation remain visible.
Operational mistakes are usually direction or shift mismatches. Because shift 23 encoding matches shift 3 decoding, users can become confused when two different-looking settings produce the same transformation. Normalizing and displaying the intended direction keeps the model clear.
- A wrong shift produces another reversible substitution, not an integrity error.
- The cipher cannot detect whether decoded text is correct.
- Non-English letters are preserved rather than rotated through an invented alphabet.
- ROT13 is obfuscation and can be reversed by the same operation.
- Do not use Caesar output for secrets, authentication, storage protection, or secure transport.
Caesar compared with ROT13 and modern encryption
ROT13 is exactly the Caesar cipher with shift thirteen. Because thirteen plus thirteen equals twenty-six, encoding and decoding are identical. Atbash is another classical substitution, but it reverses the alphabet rather than applying a constant rotation.
Modern authenticated encryption such as AES-GCM or ChaCha20-Poly1305 operates on bytes with large secret keys, nonces, and integrity tags. It is designed to resist attackers who know the algorithm. Caesar relies entirely on hiding one of twenty-six shifts and offers no authentication.
ROT13
A fixed shift of 13 used for casual obfuscation. It has the same security level as every other Caesar shift.
Atbash
Maps A to Z, B to Y, and so on. It is also a fixed monoalphabetic substitution and is not secure.
Authenticated encryption
Uses a real secret key and integrity verification. Choose a maintained cryptographic library instead of implementing it in a text utility.