Caesar Cipher (History, Example, Variants and Security)

Caesar cipher is the most  known cipher in cryptography. It goes with other names like (Shift cipher, Caesar’s code, Caesar’s shift and Caesar’s cipher).

Caesar cipher is an examples of monoalphabetic substitution cipher. It is also a symmetric cipher as the same key is used for both encryption and decryption process.

In this guide I will be discussing:

Where this Caesar cipher originates from, its uses, resources for further learning, online tools for encoding and decoding Caesar cipher and implementation of this encryption algorithm in various programming languages.

A brief history of Caesar cipher:

It was invented by Julius Caesar with the aim of sending messages to his troops. He used a shift of 3 in the letters of the alphabet to encrypt messages.

Augustus also used Caesar cipher with a slight variation:

He shifted every letter with one space to the right to scramble the message.

1) How to solve Caesar cipher

Basically this is a substitution cipher where each letter of the plaintext is replaced with a letter that corresponds to a given letter that has been either shifted up or down the alphabet.

What you come up after the encryption has been done is called ciphertext. This text is completely scrambled and unreadable.

How to encrypt using Caesar cipher:

For example if I decide to use a shift of 3 to encode my message:

“A” will become “D”, “B” will become “E”, “C” will become “F” and so one down the alphabet.

To encode a simple message is equally easy as all you have to do is match each letter of the plaintext to the corresponding shifted letter to come up with the ciphertext.

Here is an example of Caesar cipher:

Plaintext: Learning cryptography is fun.

Ciphertext: Ohduqlqj fubswrjudskb lv ixq

How to decrypt Caesar cipher:

To decrypt a message encrypted with Caesar cipher requires you to have the key used. The easy way to go about is generate a table using the key that was used to encrypt the message.

The benefit of this step is to enable you to quickly decode the message. After you have the table decryption process is as easy as match every letter of the ciphertext to the right letter on the table to get the original message.

Here are is an example (use shift 3) for you to decrypt:

Ciphertext: Vkliw flskhu lv dzhvrph

Plaintext: ?

How to recognize Caesar ciphertext:

Often messages encoded using Caesar cipher have a shift in their frequency analysis diagram that is equal to the selected shift.

Also the index of coincidence of ciphertext is the same as that of the plaintext.

How to decipher Caesar without knowing the shift:

The best method involves testing all shifts, this depends on the alphabet used. For example if the alphabet has 26 letters, then you only have 25 shifts to try.

How to encrypt digits and numbers using Caesar cipher:

Normally Caesar cipher is only used with letters of the alphabet. But there are various ways it can be used to encrypt numbers.

  • Write the numbers in Roman numerals, thus the numbers become letters in order to encode them.

Here is an example:

Digit “9” becomes letters “IX” which becomes letters “LA” when a shift of 3 is applied.

  • Shift the numbers with the same shift as the letters.

Here is an example:

Digit “9” would become digit “12” when a shift of 3 is used.

  • You can also integrate numbers in the alphabet.

Here is an example:

Consider alphabet “ABCDEF123”, digit “21” would become letters “BA” when a shift of 3 is applied.

Why the name Caesar Cipher:

Julius Caesar used this technique to send messages for military purposes. For instance with Cicerone using shift 3.

What is August Cipher:

This is simply the name given to Caesar cipher with a shift of 1.

What are other Caesar Cipher names:

Caesar cipher is also known as Shift Cipher.

Here are Caesar variants with hidden shifting property:

  • CD code, C = D, the shift is 1
  • Jail (JL) code, J = L, the shift is 2
  • Ellen (LN) code, L = N, the shift is 2
  • Cutie (QT) code, Q = T, the shift is 3
  • Eiffel (FL) code, F = L, the shift is 6
  • WC code, W = C, the shift is 6
  • Empty (MT) code, M = T, the shift is 7
  • Baden Powell (scoutism founder), B = P, the shift is 14
  • Any (NE) code, N = E, the shift is 17
  • See You (CU) code, C = U, the shift is 18
  • I See (IC) code, I = C, the shift is 20
  • Easy (EZ) code, E = Z, the shift is 21
  • CEASAR (with a wrong spelling) where E=A or A=E, the shift is either +4 or -4 (=22)
  • Any 2-letter code that can give an association between a crypted char and the plain one
  • ROT13 code, the shift is 13 and reversible
  • ROT5 code for digits, the shift is 5 and reversible
  • ROT47 code for ASCII printable characters, the shift is 47 and reversible
  • More generally ROT-N with N the shift, if N < 26 then the latin alphabet is used, else it can be any other custom alphabet.

How to cipher CAESAR with the Caesar code:

Here are 25 ways to cipher Caesar by itself:


How to write Caesar Cipher in pseudo-code:

For N from 1 to Text Length Do

Take C = Nth character of Text

Calculate R = the rank of C in the alphabet

Calculate R2 = (R + Shift) Modulo 26

Write the letter with rank R2 in the alphabet

End For Loop

When was Caesar Cipher Invented:

Though the exact date of creation and author are not known, this code is named after Julius Caesar, born in 100 BC. He used this substitution code for his military communications.

2) Caesar cipher mathematics

Consider the following: a=0, b=1…..and z=25. Each letter of the alphabet is assigned a number.

Caesar cipher encryption formula is given by:

E(x) = ( x + p) mod 26

The “P” represents the shift applied to each letter. You can think of it as the key too. The “x” is the letter you want to encrypt or decrypt.

Caesar cipher decryption formula is given by:

E(x) = ( x – p) mod 26

Note that the result of each process is undergoes modulo division. This is to ensure that if a letter is shifted past the end of the alphabet you are using, it will be wrapped at the beginning.

3) Caesar variations

ROT13 cipher is an example of Caesar cipher with a shift of 13 as the key. It is commonly used to hide offensive words in newspapers and forums.

Also a more complex cipher like vigenere uses some principles of Caesar’s code for the encryption process.

4) How to break (crack) Caesar cipher

It is very easy to break this cipher considering that there are only 25 possible keys.

It should not be used today as it’s a weak (insecure) cipher and offers no security at all.

Caesar cipher is very vulnerable to attacks considering the power of modern computers that can evaluate a lot of combinations in just seconds.

Here are ways to crack this cipher:

  • Brute force attack: If you don’t have the key you easily decrypt a message by trying all the 25 possible combinations.
  • Frequency analysis: since the structure of the message doesn’t change that much, you can easily recognize patterns in the letters and with enough time you will be able to decode the message without even requiring a key.

For example if the language used is English, you can start by replacing the most frequent letter in the message with letter “e”.

5) Caesar cipher tools and resources

If you want to learn and read Caesar cipher easily there are several tools that will help you do just that. Use these tools to write simple Caesar cipher message and learn how it works.

You can encode and decode to text and English or the Language of your choice.


6) Caesar Cipher Code Snippets

Add Comment