Caesar cipher

The Caesar cipher replaces every letter with the letter a fixed number of places further along the alphabet. With a shift of 3, A becomes D, B becomes E, and at the end of the alphabet you start again: X becomes A, Y becomes B, Z becomes C. To decrypt, you shift back by the same number. The Roman writer Suetonius reports that Julius Caesar used a shift of 3 for his private letters, which gave the cipher its name.

The shift is the key. Sender and receiver must both know it, which makes the Caesar cipher a very simple form of symmetric encryption.

The Caesar cipher as a calculation

Number the letters from A = 0 to Z = 25. Encrypting a letter p with the key k is then an addition with remainder:

  • Encrypt: c = (p + k) mod 26
  • Decrypt: p = (c − k) mod 26

Example with k = 3: H is 7, and 7 + 3 = 10, which is K. For Y: 24 + 3 = 27, and 27 mod 26 = 1, which is B. A shift of 26 brings every letter back to itself, so there are only 25 useful keys. ROT13, the code used for hints on geocaching.com, is a Caesar cipher with a shift of 13; because 13 + 13 = 26, encrypting twice gives the original text back.

Why it is not secure

  • Too few keys. Anyone can try all 25 shifts by hand in a few minutes, a computer in a fraction of a second. This is called a brute-force attack.
  • Patterns survive. Every E in the message becomes the same cipher letter, and word lengths stay visible. Frequency analysis finds the shift from a long enough text without trying anything.

That makes the Caesar cipher a great first step for learning how encryption works, and a good example of what modern ciphers like AES must avoid. Never use it to protect real data.

Try it

Turn the cipher wheel in the projector mode, or paste a Caesar text into the decoder: it tries all 25 shifts and ranks them. Teachers find a printable worksheet with answer key in the classroom area.

Searches the list of pages on this site. What you type stays in your browser.