Caesar Cipher

Definition, how it works, and an interactive tool.

• Read time: ~5 min

What is the Caesar cipher?

The Caesar Cipher is one of the oldest and simplest encryption techniques ever created. It works by shifting each letter of the alphabet a fixed number of positions forward. For example, with a shift of 3, A→D, B→E, and so on, until the alphabet “wraps around” and the letters start again from A.

This cipher usually works with the Latin alphabet (A–Z). Accents and special symbols are normalized for simplicity, and the letter ñ/Ñ is often left unchanged for compatibility. Although it’s no longer used for real-world data protection, it remains an excellent way to understand the basic principles of substitution ciphers.

How it works

The Caesar Cipher operates by shifting every letter in a message by a fixed number of steps, defined by a numerical key between 0 and 25. Each letter is replaced with another one further down the alphabet. When the end of the alphabet is reached, it continues from the beginning — this is a mod 26 operation.

To encrypt, the shift value is added to each letter’s position. To decrypt, the same value is subtracted. It’s important to note that this method provides no integrity or authenticity: it only hides the message superficially, and can easily be broken by testing all possible keys.

Formulas

Encryption:   Cᵢ = (Pᵢ + s) mod 26
Decryption:   Pᵢ = (Cᵢ - s + 26) mod 26

where:
  Pᵢ = index (0–25) of the i‑th plaintext letter
  s  = fixed shift (0–25)
  Cᵢ = index (0–25) of the i‑th ciphertext letter
            

Example

Quick example

Let’s encrypt the phrase HELLO WORLD using a shift of 3. Each letter moves three positions forward in the alphabet, resulting in KHOOR ZRUOG.

For instance, H becomes K, E becomes H, and L becomes O. Every letter is transformed in the same way. To decrypt the message, simply reverse the process by subtracting the shift value.

If your text includes spaces, punctuation, or numbers and you have “preserve” checked, those characters will remain unchanged. This makes it easier to work with mixed text while keeping readability.

History

  • This cipher was used over two thousand years ago by Julius Caesar to send confidential military messages to his generals.
  • Its simplicity made it a cornerstone of classical cryptography and an ideal example to teach the concepts of substitution and encryption keys.
  • Although completely insecure by modern standards, it remains a historical and educational tool for understanding the foundations of encryption.

Classic attacks

  • Brute force: testing all 25 possible shifts until the correct one is found. It’s the simplest attack and demonstrates how easily this cipher can be broken.
  • Frequency analysis: studying the frequency of letters in the encrypted text. In English, for example, the letter E appears most often, so if a certain letter shows up frequently in the ciphertext, it likely represents E.
  • Known plaintext: if the attacker knows part of the original message, the shift can be calculated immediately, revealing the entire text.
Pros and cons

Pros

  • Very easy to understand — a perfect introduction to substitution ciphers.
  • Ideal for educational and historical demonstrations.
  • Can be implemented manually or in just a few lines of code.

Cons

  • Extremely insecure: only 25 possible keys make it easy to brute-force.
  • Letter patterns can be quickly identified through frequency analysis.
  • Provides no message integrity or authenticity — only superficial obfuscation.

Caesar Cipher Tool

Negatives and large values are accepted; normalized to 0–25 (e.g., 52→0, −1→25).