The Caesar cipher

The Caesar cipher shifts each letter by k positions in the alphabet. Change the shift and see why such a small key space makes it easy to break.

The Caesar cipher
Mathematics · Cryptography · The Caesar cipher
Shift kk3
The Caesar cipher is easy to break because there exist only…
shift k
3
plaintext
MATURA
ciphertext
PDWXUD
key space
25
🎯 Challenge: encrypt a letter
streak: 0

I’ll give you a letter and a shift k — give its ciphertext. c = (x + k) mod 26 (A = 0 … Z = 25).

What just happened?

We replace each letter with the letter kk positions away in the alphabet. The bottom strip is simply the alphabet rotated by kk — which is why it “rotates” when you move the slider.

The Caesar cipher (modular arithmetic):

Number the letters: A=0, B=1, …, Z=25A=0,\ B=1,\ \dots,\ Z=25. Then encryption and decryption are addition modulo 26:

c=(x+k) mod 26x=(c−k) mod 26c = (x + k)\bmod 26 \qquad x = (c - k)\bmod 26

— xx is the number of the plaintext letter, kk is the key (the shift), cc is the number of the ciphertext letter. “mod 26” wraps the alphabet, so after ZZ we return to AA.

Why is it a weak cipher?

The whole secret is a single number k∈{0,1,…,25}k \in \{0,1,\dots,25\}. The shift k=0k=0 changes nothing, so only 25 meaningful keys remain. To break the cipher by “brute force”, it is enough to check all 25 shifts and see which gives readable text.

Why you need this for the exam:

It is the simplest example that a cipher = a function on numbers, and that security depends on the size of the key space. By understanding c=(x+k) mod 26c=(x+k)\bmod 26, you practise congruences and the  mod \bmod operation — tools from the number-theory topic.

Remember: the Caesar cipher is c=(x+k) mod 26c=(x+k)\bmod 26, and its key space has only 25 elements — trivially small, so brute-force breaking is instant.

Illustrative model · NexTutor Virtual Laboratory

Enjoyed the experiment? Share it.

It's free — send it to friends from school.

Theory & formulas

Encryption

Each letter (numbered 00–2525) is shifted by the key kk: c=(x+k) mod 26c=(x+k)\bmod 26

Decryption

x=(c−k) mod 26x=(c-k)\bmod 26

Weakness

There are only 2525 keys — a brute-force attack checks them all in a fraction of a second. It is a shift cipher, a special case of a substitution cipher.

Notation: xx number of the plaintext letter, cc of the ciphertext letter, kk the shift (the key).

Frequently asked questions

›

Why is the Caesar cipher weak?

Because the key is just a shift of 1–25 — it is enough to check all 25 possibilities (brute force).

›

How does the Caesar cipher work?

Letter x → (x+k) mod 26; decryption: (c−k) mod 26.

Teaching? Embed this experiment on your site.

Free widget — paste it on your school site, blog or notes. It links to the full version.

Teaching a class or tutoring? Guide students in NexTutor →