Omni Calculator logo

How does a Caesar cipher work​? A simple guide to this classic encryption method

Prepare yourself to create a secret message or decode a Caesar cipher.​ The Caesar cipher is one of the simplest and oldest methods of cryptography. Created by the famous Roman emperor Gaius Julius Caesar, this cipher method played a crucial role in the history of Rome and in the evolution of encryption.

The process to encode/decode a message with this cipher is very simple; you just need to label your alphabet with numbers and shift the letters by a fixed value. Caesar usually used a three-letter shift to the right. Then, you will be able to write your secret message or decipher a text sent by one of your Praetorian generals.

You can use the famous Caesar wheel to build your messages, or save your energy and create your own ciphertext in different alphabets with our excellent Caesar cipher shifter.

But, if you want to know in detail the answer to the question: "How does a Caesar cipher work?", stay with us in this article, where we will see the following topics:

  • What is the Caesar cipher?
  • How does a Caesar cipher work​?
  • Using the Caesar cipher decoder – an example.
  • What is the Caesar wheel​?
  • How many possible keys exist in the Caesar cipher?
  • Is the Caesar cipher still used today?
  • And much more.

Ad Cīfram Caesaris, Eāmus!

Let's go back to Greece in 48 BCE. Near the region of Pharsalus, a battle changed the course of the Roman Civil War, fought between Julius Caesar and Pompey. This battle, now known as the Battle of Pharsalus, settled the defeat of Pompey's army and marked a milestone in Caesar's ascension to the position of dictator perpetuo (dictator for life).

Pharsalus was one of the most important battles won by Julius Caesar, the notorious Roman general and emperor. Besides his Roman legions, historians consider that Caesar had another special weapon to fight and win his battles: cryptography. Caesar developed one of the simplest and oldest methods of cryptography, using it to encode messages to his allies and generals. This method is now called the Caesar cipher.

The Caesar cipher is an example of monoalphabetic cryptography, which means that the letters of a single alphabet are shifted by a fixed number of positions. In practical terms, this cipher uses numbers to identify each letter of the alphabet, in such a way that A=0,B=1,C=2,...,Z=25A=0,\, B=1,\, C=2,\, \mathrm{...},\, Z = 25. Then, you need to set a specific shift (key) to your original alphabet and replace each letter of the plaintext with the shifted letter of the ciphertext.

The historians say that Caesar usually encoded his messages by shifting the letters three steps to the right. Therefore, AA becomes DD, BB becomes EE and so on. Certainly, Caesar was not the first person to invent secret writing, but he systematically used and popularized this specific method of cryptography.

Now that you know the history of the cipher, let's examine the mathematics behind it in detail. As you may suspect, we can use algebra to encode or decode a Caesar cipher​. The process to encrypt a message is described by the equation below:

C=(P+K)mod26C = \left(P+K\right) \,\mathrm{mod}\, 26

where:

  • CC — Ciphertext letter number;
  • PP — Plaintext letter number;
  • KK — number of positions to shift; and
  • mod\mathrm{mod} — Modulo operator.

This equation means that the sum between PP and KK needs to be lower than 2626 (mod26\mathrm{mod}\,\, 26), otherwise, you need to subtract 2626 from the sum to get the correct encoded letter. Find more information about the modulo operator by accessing our modulo calculator.

You can decode a message written with the Caesar cipher using the formula:

P=(CK)mod26P= \left(C-K\right) \,\mathrm{mod}\, 26

which basically represents the reverse process of encoding. Note that once more, the difference between KK and CC is modulated by 2626 (for Latin alphabet).

🙋 Are you looking for more tools for encoding text? Then, you need to check out our Morse code calculator and Vigenère cipher calculator.

It is your time to decode a Caesar cipher. Suppose that you received this message from Julius Caesar "srpshb hvfdshg". What does it mean? To find the answer, you need to remember that Caesar used a key=3\mathrm{key} = 3 to encrypt this message, shifting the letters to the right. Here, we are considering a Latin alphabet for simplicity; however, historically, this message would likely have been written in Greek. So, all you need to do is shift each letter of the ciphertext three times to the left, unveiling the secret message:

S3PR3OP3MS3PH3EB3Y\begin{gather*}\rm \quad S \\[-2px]\rm -3 \\[-2px]\rm \quad P \end{gather*}\,\, \begin{gather*}\rm \quad R\\[-2px]\rm -3 \\[-2px]\rm \quad O \end{gather*} \,\, \begin{gather*}\rm \quad P\\[-2px]\rm -3 \\[-2px]\rm \quad M \end{gather*}\,\, \begin{gather*}\rm \quad S\\[-2px]\rm -3 \\[-2px]\rm \quad P \end{gather*}\,\, \begin{gather*}\rm \quad H\\[-2px]\rm -3\\[-2px]\rm \quad E \end{gather*}\,\, \begin{gather*}\rm \quad B\\[-2px]\rm -3 \\[-2px]\rm \quad Y \end{gather*}\,\,
H3EV3SF3CD3AS3PH3EG3D\begin{gather*}\rm \quad H \\[-2px]\rm -3 \\[-2px]\rm \quad E \end{gather*}\,\, \begin{gather*}\rm \quad V\\[-2px]\rm -3 \\[-2px]\rm \quad S \end{gather*} \,\, \begin{gather*}\rm \quad F\\[-2px]\rm -3 \\[-2px]\rm \quad C \end{gather*}\,\, \begin{gather*}\rm \quad D\\[-2px]\rm -3 \\[-2px]\rm \quad A \end{gather*}\,\, \begin{gather*}\rm \quad S\\[-2px]\rm -3\\[-2px]\rm \quad P\end{gather*}\,\, \begin{gather*}\rm \quad H\\[-2px]\rm -3 \\[-2px]\rm \quad E \end{gather*}\,\, \begin{gather*}\rm \quad G\\[-2px]\rm -3 \\[-2px]\rm \quad D \end{gather*}\,\,

Thus, the decoded message is "Pompey escaped", revealing that his enemy was able to flee from the battlefield. You can check the decoding of this ciphertext or create your own cipher messages instantaneously with our Caesar cipher shifter.

The Caesar wheel​, also known as a cipher disk or cipher wheel, is a tool formed by two rotatable disks with the alphabet printed on them. The outer disk is fixed and corresponds to the plaintext, while the inner wheel rotates to apply the shift, creating the substitution mapping that encodes your message. You can use the Caesar wheel to decrypt a message by finding the ciphertext letter in the inner wheel and reading the corresponding plaintext letter in the outer disk.

The Caesar cipher is a monoalphabetic type of cipher, which means it uses a single alphabet to map the encoded and the decoded texts. Therefore, the maximum number of keys will depend on the maximum number of letters in your alphabet. If you consider the Latin alphabet, there are 26 letters, which means that you can shift from 0 to 25. Since 0 does not correspond to a shift between the ciphertext and the plaintext, you have 25 possible keys for the Caesar cipher.

Nowadays, the Caesar cipher is not used for serious encryption. Since it is a monoalphabetic cipher, the encoded messages can be easily broken using simple algorithms. However, the Caesar cipher is still applied in studies of basic cryptography, in coding challenges, in puzzles, and in games.

This article was written by João Rafael Lucio dos Santos and reviewed by Steven Wooding.