# An introduction to Caesar Cipher in Cryptography

We all use the internet daily for basic searching and browsing

to talking on with friends and family on the internet. There seem to be some basic activities but apart from these people do various work too. Something like transactions, buying, and selling on online marketplaces. And to support these activities, we have a great infrastructure in the form of the internet. To complete these activities safely, security is an important part of it. And if we are talking about security how can we miss cryptography? So, in this article, we will learn about Caesar cipher, one of the cryptographic methods.

## What is Caesar cipher?

Caesar Cipher is one of the simplest methods in cryptography. And after reading the name you might be thinking of Julius Caesar. So, yes it’s connected to Julius Caesar. He used this method to encrypt his messages using the Caesar cipher encryption method. Based on some logic we can encrypt our message or text as a sender. And based on the logic receiver can decrypt it by substituting some letters. We will discuss this logic in the next section.

## Cryptography algorithm for the Caesar cipher

Let’s understand Caesar cipher in cryptography. We’ll need a text and a number to use this method. Text can only contain alphabets. As we know every alphabet A to Z has a number from 1 to 26. And the number that we have to choose should be a number from 1 to 26 too.

So, our text is **CODEDAMN** and the number is **3**. In the word CODEDAMN, every letter has a ranking from 1 to 26 and in this case, C has 3, O has 15, D has 4, and so on. Now we will add 3 to each letter and it will become **FRGHGDPQ.** This is what we call caesar cipher encryption.

Now you may be thinking why we took the number 3, we can take any number from 1 to 26. Here, C is the first letter and it’s on the 3rd number. So the receiver can understand quickly which number is to be added to decrypt the message. But it’s not necessary we can take any number like 10, 16, or anything. Here, the receiver has to put in some more effort.

We can also decrypt it. After encryption the value of the first letter F is 6, R is 19, and, so on. By decreasing 3 from each one we can decrypt it. And this is caesar cipher decryption.

### Input

We have to take two inputs to implement caesar cipher in cryptography.

- A number, which should be between 0 to 25 in form of an integer.
- A plaintext or message that we want to encrypt in form of a string.

### Procedure

- You have to take two inputs one a number and a string which will be a text.
- Create a loop that will run up to the length of the string.
- If letters are in uppercase and lowercase make conditions differ according to them.
- In conditions, add according to the given integer in every letter.
- Return the encrypted or decrypted text.

### Time complexity

In order to encrypt or decrypt the text loop has to be run for every letter. That’s why time complexity will be O(N).

### Auxiliary Space

For space complexity, It will depend on the number of letters in the string. And it leads to the space complexity of O(N).

## Cryptography based on Caesar cipher is weak

Because of its simple way of encrypting the text. In modern days, where we have computers that can process copious amounts of data in so much less time. It’s not very effective that’s why it’s a weak method in cryptography.

But still, even if it’s not very effective. It lays a good foundation to understand more about cryptography. And how it evolves with time.

Let’s move forward with a little bit more formulas, explanations, and technical terms.

### Plaintext

Plaintext usually refers to raw data, simple text,

unencrypted, or the original message in cryptography.

### Cipher

Cipher usually refers to the data which is encrypted, encoded

, or the secret text which hides the actual meaning of the text.

## Features of Caesar cipher

The main goal of any cryptography method is to convert plaintext into cipher text. In Caesar cipher, we have the Encryption Formula and Decryption formula.

### Encryption Formula

The formula of Caesar cipher encryption is **En(x) = (x + n) mod 26.**

Here, **En(x)** stands for Encryption of x,**x** is the letter that is going to be encrypted,

and** n** is the number that is going to be added.**mod 26 **is the modulus.

To know more about the modulus in cryptography read this.

### Decryption Formula

The Formula for Caesar cipher decryption is **Dn(x) = (x – n) mod 26**.

here,**Dn(x)** represents the Decryption of x,**x **is the letter that is going to be decrypted,**and **n is the number that is going to be reduced.

## Advantages of Caesar cipher

- It’s very simple to learn and implement.
- Require very less amount of inputs and limited data.
- Required fewer computing resources.

## Disadvantages of Caesar cipher

- In modern days, encryption can be broken down easily.
- It contains a consistent pattern, anyone can track the pattern and decrypt the text easily.

## Conclusions

- Caesar Cipher is one of the simple methods in cryptography.
- This method requires two inputs one a number and a plaintext.
- The Time Complexity and Space Complexity both are O(N).
- The encryption formula is En(x) = (x + n) mod 26 and the Decryption formula is
**Dn(x) = (x – n) mod 26**. - While it’s easy to implement but it can’t withstand the modern era. As computers can break it easily.

## Frequently Asked Questions to Resolve (FAQs)

### What is the Caesar cipher in cryptography?

Caesar cipher is an algorithm in cryptography that takes two inputs a number and a text. It encrypted the text with the help of a number.

### What is the Caesar cipher and how does it work?

Caesar Cipher is a cryptographic algorithm that takes two inputs: a plaintext and a number. It follows caesar cipher encryption method to encrypt the text. And caesar cipher decryption method to decrypt the text.

### What are the 3 ciphers?

There are Simple Substitution Cipher, Caesar Cipher, and Mono-alphabetic ciphers.

### Is Caesar cipher encoding or encryption?

Caesar cipher is encryption.

### How does the Caesar cipher work?

Caesar cipher is an algorithm that takes two inputs. First, it takes a text and a number. This text only contains the alphabet. Now, according to this number, every letter in the text is replaced with another text. And at last, it gives an encrypted text.

### Sharing is caring

Did you like what Sunny Shah wrote? Thank them for their work by sharing it on social media.

- Difference Between SSL and TLS
- VPN vs Proxy vs Tor: Learn the key differences in 2023