Skip to main content
CC

Caesar Cipher

Encipher and decipher text with the classic Caesar substitution cipher — you choose the shift value from 1 to 25.

Did you like the tool? Thanks!
Share:

Choose a shift (1–25) and direction. Decrypting with shift N equals encrypting with shift 26−N. Case is preserved.

How to Use Caesar Cipher

Type your text, choose a shift value from 1 to 25, and see it transformed letter by letter. Toggle between Encrypt (shift forward) and Decrypt (shift backward). Preserves case and passes non-alphabetic characters through unchanged. Copy the result with one click.

About Caesar Cipher

The Caesar cipher is the most famous substitution cipher in history — named, of course, after Julius Caesar, who reportedly used a shift of 3 to protect military messages (A becomes D, B becomes E, C becomes F, and so on). It is also the simplest: pick a number between 1 and 25, and shift every letter in the alphabet forward by that many positions, wrapping around from Z back to A. To decrypt, shift backward by the same amount. That is the entire algorithm, and it is why the Caesar cipher is the first thing taught in any cryptography or classical-cipher course — it demonstrates the core ideas of a key (the shift value), a substitution alphabet, and the brute-force vulnerability of a keyspace too small to resist enumeration, all in about three lines of code.\n\nDespite being trivially breakable (there are only 25 possible shifts; a computer can try all of them in less than a millisecond), the Caesar cipher holds an important place in the history of ideas. For centuries after the Roman Empire fell, it was considered genuinely secure, because the people intercepting Roman messages did not know that a substitution cipher was being used — the very concept of a cipher was the secret, not the key. Once the method is known, the cipher is broken. This pattern — security through obscurity, a method that works only as long as the method itself remains hidden — has recurred throughout the history of cryptography and computer security, and the Caesar cipher is the canonical example used to explain why it fails.\n\nThis tool lets you choose any shift from 1 to 25 (0 and 26 are the identity — no change — and 13 is the special case known as ROT13, which has its own dedicated tool in this collection because of its self-inverse property). You can toggle between Encrypt mode (shift forward) and Decrypt mode (shift backward) — decrypting with shift equals N is exactly the same as encrypting with shift equals 26 minus N. For example, decrypting a shift-3 message is the same as encrypting with shift 23. The tool also handles the edge case where users paste text that already contains both shifted and unshifted content — the output is always consistent across the entire input, applying the chosen shift to every applicable letter.

Details & Tips

Shift mechanism in detail: for each character in the input, if it is an uppercase letter (A-Z, code points 65-90), the tool computes ((charCode - 65 + shift) mod 26) + 65 for encryption and ((charCode - 65 - shift + 26) mod 26) + 65 for decryption. The modulo 26 handles wraparound — shifting Z (code point 90) by 1 for encryption gives 90+1=91, which is the code point for a bracket character, not A — taking (90-65+1) mod 26 equals 0, plus 65 gives 65, which is A. For lowercase (a-z, code points 97-122), the same formula with 97 as the base: ((charCode - 97 + shift) mod 26) + 97.\n\nThe modulo operation for negative shifts (decryption) requires careful handling because the standard modulo operator in many languages returns a negative remainder when the dividend is negative — for example, -1 mod 26 returns -1 instead of 25. The tool adds 26 before applying modulo 26 to guarantee the result is always in the range 0-25, which prevents off-by-one errors at the A and Z boundary during decryption.\n\nEdge cases: shift values 0 and 26 are rejected with an error since they would produce no transformation — the widget requires a shift between 1 and 25. Shift equals 13 is the ROT13 cipher and is equivalent to the dedicated ROT13 tool. A shift outside the valid range 1-25 is rejected with a clear error rather than producing a silently wrong output. Empty input returns empty output. Text containing no alphabetic characters passes through unchanged.\n\nKnown weaknesses (for educational purposes): the keyspace is only 25 — a brute-force attack requires at most 25 attempts, which a computer can do in under a millisecond. Letter frequency analysis is even more efficient — in English, E is the most common letter (about 12.7% frequency), and the most common letter in the ciphertext is almost certainly the encryption of E, immediately revealing the shift. The cipher does not hide word boundaries or punctuation, providing structural clues to an attacker. It is deterministic and has no notion of an initialization vector, so the same plaintext always encrypts to the same ciphertext.

Frequently Asked Questions

What shift did Julius Caesar actually use?
According to Suetonius, Caesar used a shift of 3 (A becomes D, B becomes E, C becomes F). There is no direct archaeological evidence, but the historical account is consistent and widely accepted.
How many possible Caesar cipher shifts are there?
25 meaningful shifts (1 through 25). Shift 0 and 26 are the identity and do not change the text. This small keyspace is why the cipher is trivially breakable by brute force — a computer can try all 25 in under a millisecond.
What is the relationship between encrypt and decrypt shifts?
Decrypting with shift N is the same as encrypting with shift (26 minus N). For example, a message encrypted with shift 3 can be decrypted either by decrypting with shift 3 or by encrypting again with shift 23.
Is the Caesar cipher the same as ROT13?
ROT13 is a specific Caesar cipher with shift equal to 13. It is special because 13 is half of 26, making it self-inverse — encrypting twice returns the original. The Caesar cipher tool generalizes this to any shift 1-25.
Does the cipher change numbers, punctuation, or spaces?
No. Only the 26 English alphabet letters (A-Z, a-z) are transformed. Digits, punctuation, whitespace, and all other characters pass through unchanged.
Is the Caesar cipher secure?
No — and it has not been for centuries. With only 25 possible keys, it is trivially broken by trying every shift (brute force) or by looking at letter frequencies (E is the most common letter in English, so the most common ciphertext letter is likely E encrypted). Use AES-GCM or ChaCha20-Poly1305 for actual security.
Why is the Caesar cipher still taught if it is so weak?
It is the simplest possible example of a substitution cipher, introducing the core cryptographic concepts — plaintext, ciphertext, key, encryption, decryption, brute-force attack, and frequency analysis — without requiring any mathematical background. It is the "Hello World" of cryptography.
How does the tool handle the wrap from Z back to A?
Using modular arithmetic (mod 26). Shifting Z by 1 gives A, shifting Z by 2 gives B, and so on. The same logic applies in reverse for decryption — shifting A backward by 1 gives Z.
Is my text sent to a server?
No. All encryption and decryption runs in your browser using JavaScript — nothing you type is transmitted, logged, or stored anywhere.
Can I use this to learn about cryptography?
Yes — it is perfect for that. Try encrypting a message with one shift, then pretend you intercepted it and try to figure out the shift on your own. Use a known English text and observe which ciphertext letter appears most often — it probably corresponds to E. This is exactly how frequency analysis works.

Part of These Collections

Also Available As

caesar cipher, caesar cipher encoder, caesar cipher decoder, caesar cipher online, shift cipher, substitution cipher, caesar cipher translator, rot cipher

Found a Problem?

Let us know if something with Caesar Cipher isn't working as expected.

Thanks — we'll take a look.