RU EN ES 中文

Caesar Cipher

The simplest shift cipher, used by Julius Caesar two thousand years ago. This is where the history of cryptography began.

Why study the Caesar cipher?

Imagine you are a general in ancient Rome. You need to send an order to your troops, but the messenger could be captured by the enemy. How do you make sure that even if the message is intercepted, no one but your generals can understand it?

That is exactly the problem Julius Caesar solved more than 2000 years ago. His method — a simple shift of the alphabet's letters — became the first step toward modern cryptography.

Today the Caesar cipher isn't used to protect real data — it can be cracked in seconds. But it remains a perfect teaching tool, because it clearly demonstrates fundamental principles:

How does the Caesar cipher work?

The idea is brilliantly simple: every letter in the message is replaced with another letter a fixed number of positions away in the alphabet. That number is called the shift or the key.

1

Assigning positions

Every letter of the alphabet gets a numeric position: А=0, Б=1, В=2... Я=32 (for the Russian alphabet).

2

Applying the shift

The key is added to each letter's position: new_position = (old_position + key) mod N, where N is the size of the alphabet.

3

Reversing the transformation

To decrypt, the receiver subtracts the key: old_position = (new_position - key + N) mod N.

The math behind the Caesar cipher
🔐 Encryption
C = (P + K) mod N
Example:
Encrypting the letter П with shift 3
П = 16th letter (0-indexed), K = 3
(16 + 3) mod 33 = 19 → Т
🔓 Decryption
P = (C − K + N) mod N
Example:
Decrypting Т with shift 3
Т = 19, K = 3, N = 33
(19 − 3 + 33) mod 33 = 16 → П
Why does this work?
The mod N operation makes the alphabet "wrap around": after the last letter comes the first one again. This simple but powerful mathematical property underlies many modern ciphers.
The key can be anywhere from 1 to N−1
* In the game, a cipher disk rotates, visually showing how plaintext letters map to ciphertext letters.
Key takeaway: The magic of the Caesar cipher lies in modular arithmetic. The "mod N" operation makes the alphabet "wrap around": after the last letter comes the first one again. It's a simple but powerful principle underlying modern cryptographic algorithms.

Try the cipher yourself

In the interactive "Caesar Cipher" simulation you won't just read the theory — you'll become a cryptographer:

You'll see the green disk (plaintext) and the blue disk (ciphertext) rotate, vividly showing the symmetry between encryption and decryption.

Main lesson: The game shows not just the math of the cipher, but also a secure transmission protocol: the key is sent first, then the encrypted message. This is a fundamental idea underlying all modern data-protection systems.
For the curious

Historical background

The cipher Julius Caesar used was described by the Roman historian Suetonius. Caesar shifted letters by 3 positions, but the principle works with any key. For a long time the method was considered secure enough, until Arab scholars developed frequency analysis (9th century).

Why is the Caesar cipher weak?

Despite its historical importance, the Caesar cipher is easy to break:

  • Small key space — only N−1 possible shifts (32 for the Russian alphabet)
  • Frequency analysis — letters occur with different frequencies in a language; comparing ciphertext frequencies to reference ones can recover the key
  • Brute-force attack — you can try all 32 options by hand in a couple of minutes

Topics for further study

If you want to dive deeper into cryptography, here are some key topics:

Frequency analysis

How language statistics help break ciphers: letter, bigram, and trigram frequencies

Vigenère cipher

A polyalphabetic cipher considered unbreakable for three centuries

One-time pad

The only theoretically unbreakable cipher: a key as long as the message, used only once

Modern block ciphers

How simple substitution evolved into AES, the Russian "Kuznyechik" standard, and other algorithms

Cryptanalysis in Python

Practical scripts for frequency analysis and attacks on the Caesar cipher

Russian standards

GOST 28147-89 "Magma," GOST R 34.12-2015 "Kuznyechik," and the "Streebog" hash function

Fun facts

  • The Caesar cipher was used by the Russian army during World War I — and was routinely broken by the enemy
  • In Hebrew there is a cipher tradition called "Atbash" — swapping the first letter of the alphabet with the last, the second with the second-to-last, and so on
  • ROT13 is a Caesar cipher variant with a shift of 13, popular online for hiding spoilers; its quirk is that encryption and decryption are the same operation
  • The game uses an extended alphabet (Cyrillic + Latin + digits + symbols), which expands the key space to over 90 options

Now that you understand the math and history of the Caesar cipher, it's the perfect time to try it in action!

In the interactive simulation you can encrypt your own message and watch every step of the process