Caesar cipher is a substitution cipher where each letter of the plaintext is replaced with another letter that has been either shifted up or down the alphabet. For example, a Caesar cipher with a shift of 3, A would be replaced by D, B would become E, and so on.
It’s the most known cipher in cryptography.
It also goes with other names like (Shift cipher, Caesar’s code, Caesar’s shift, and Caesar’s cipher).
It is also symmetric cipher as the same key is used for both encryption and decryption process.
- Read: What does cipher mean.
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.
Are you interested in finding out more about ciphers and codes?
The Codebreakers – The Story of Secret Writing book by David Kahn is what I would start with.
In this guide I will be discussing the following:
- How to solve the Caesar cipher.
- How to crack a Caesar cipher.
How to solve Caesar cipher
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 on 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:
Plaintext: Learning cryptography is fun.
How to decrypt Caesar cipher
To decrypt a message encrypted with the Caesar cipher requires you to have the key used. The easy way to go about is to 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.
- Read: Playfair Cipher.
Here are is an example (use shift 3) for you to decrypt:
Here is a tool to decrypt/encrypt Caesar automatically.
How to recognize Caesar ciphertext
Often messages encoded using the 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 the alphabet “ABCDEF123”, the 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 (scouts 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 an encrypted 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
DBFTBS, ECGUCT, FDHVDU, GEIWEV, HFJXFW, IGKYGX, JHLZHY, KIMAIZ, LJNBJA, MKOCKB, NLPDLC, OMQEMD, PNRFNE, QOSGOF, RPTHPG, SQUIQH, TRVJRI, USWKSJ, VTXLTK, WUYMUL, XVZNVM, YWAOWN, ZXBPXO, AYCQYP, BZDRZQ
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 undergoing 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.
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.
- Read: Polybius Square Cipher.
How to crack a 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.
Are you interested in learning how to break codes?
The Elementary Cryptanalysis – A Mathematical Approach book by Abraham Sinkov is what I would recommend.
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 the letter “e”.