# What is Caesar Cipher (with Example)

Are you looking for a simple method to encrypt simple messages between your friends? Then, Caesar cipher is all you need. It is considered one of the earliest and simplest ciphers you can use to scramble letters.

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, with a Caesar cipher using a shift of 3, A would be replaced by D, B would become E, and so on. It is named after Julius Caesar who invented it for the purpose of his military intelligence and correspondence. Shift cipher is symmetric in nature and letters of the alphabet are simply rearranged according to a key. Letters are not transposed making it easy to break with just a few attempts.

It is considered a weak cipher since one does not require a lot of clues to break the ciphertext. For, example with the English alphabet (abcdefghijklmnopqrstuvwxyz), there are only 25 possible key combinations you can use to brute force attack an encrypted text.

Breaking this cipher is very easy and you actually do not require a computer. A pen and paper will do just fine. Here are the reasons why Caesar cipher is considered one of the weakest forms of encryption:

The key space is very small. One can easily brute force attack by trying all 25 possible combinations to decode the message even without the initial knowledge of the key used.

The structure of the original plaintext remains unchanged. This causes the encrypted texts to be vulnerable to frequency analysis attacks.

Frequency analysis involves checking how often characters appear. Then from the data obtained, one can discover patterns and hence identify the key without having to perform a full brute force search.

Normally, before a message is transmitted, a secret code to be used in the encryption-decryption process is exchanged between the communicating parties.

This step is very important as it prevents an attacker from easily decoding the message after they successfully intercept the communication. Ciphering is then done using the key and new alphabet arrangement.

The process involves mapping each letter of the plaintext to a corresponding ciphertext character.

The simpler way to go about it is to initially generate a ciphertext alphabet using the encryption key and then you can simply substitute letters during the enciphering process.

The format of letters is not important, you can use all lowercase or uppercase characters.

To improve the security and complexity of Caesar cipher you can use symbols, digits, and integers as substitutions while constructing the cipher alphabet. You can also use a different type of alphabet like the Latin alphabet then later do conversion later when deciphering.

### How to solve a Caesar cipher

Suppose I want to encrypt this sentence “Attack at dawn” using 3 as my key. In this case, every letter of my message would be shifted as depicted in the diagram below. For example, every A in my message become D, B will become E, C is replaced by F, and so on down the alphabet. Thus, the ciphertext resulting from the above shifting of letters is “dwwdfn dw gdzq”. I can then send this scrambled message to the recipient on the other side to decode it. For best result, the encryption key should be a random number to enhance the security of Caesar cipher.

To decrypt a message you need to know the key used. Then, you simply need to create a cipher alphabet with the help of the encryption key. The final step of decoding the encrypted text is by simply replacing every letter of the cipher alphabet to the right plaintext letter.

This process is repeated for the entire ciphertext resulting in the original message that is readable.

For example, decode this encrypted text “jyfwavnyhwof” using 7 as your key.

Examples of Caesar cipher variants include:

• Vigenère cipher, a more complex algorithm that employs the letter shifting as one element of the encryption process.
• ROT13 encryption with an offset of 13.

### Implementation of this encryption scheme

• Mathematical description. First translate all characters to numbers, for example, a=0, b=2, c=2, and so on. Now we can represent the encryption function, e(x), where x is the character we are encrypting, as:

e(x) = (x + k) (mod 26)

Where k is the key or the shift applied to each letter. After applying this function, you get a number which is then translated back into a letter.

The reverse decryption function is:

e(x) = (x -k) (mod 26)

You can test out the Caesar cipher using our Caesar cipher decoder.