0% found this document useful (0 votes)
62 views16 pages

Caesar Cipher in Cryptography

The Caesar Cipher is a simple encryption method that shifts letters of the alphabet by a fixed number, originally used by Julius Caesar for military communications. It serves as a foundational technique in cryptography, demonstrating both advantages like ease of implementation and disadvantages such as vulnerability to modern decryption methods. The document also outlines the encryption and decryption processes, examples, and implementation in programming languages like C++ and Python.

Uploaded by

Arif Kamal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views16 pages

Caesar Cipher in Cryptography

The Caesar Cipher is a simple encryption method that shifts letters of the alphabet by a fixed number, originally used by Julius Caesar for military communications. It serves as a foundational technique in cryptography, demonstrating both advantages like ease of implementation and disadvantages such as vulnerability to modern decryption methods. The document also outlines the encryption and decryption processes, examples, and implementation in programming languages like C++ and Python.

Uploaded by

Arif Kamal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Caesar Cipher in Cryptography



The Caesar Cipher is one of the simplest and oldest methods of


encrypting messages, named after Julius Caesar, who reportedly
used it to protect his military communications. This technique
involves shifting the letters of the alphabet by a fixed number of
places. For example, with a shift of three, the letter ‘A’ becomes ‘D’,
‘B’ becomes ‘E’, and so on. Despite its simplicity, the Caesar Cipher
formed the groundwork for modern cryptographic techniques. In this
article, we’ll explore how the Caesar Cipher works, its significance,
and its impact on the development of cryptography with its
advantages and disadvantages.

What is Caesar Cipher Technique?


The Caesar cipher is a simple encryption technique that was used by
Julius Caesar to send secret messages to his allies. It works by
shifting the letters in the plaintext message by a certain number of
positions, known as the “shift” or “key”. The Caesar Cipher
technique is one of the earliest and simplest methods of encryption
techniques.
It’s simply a type of substitution cipher, i.e., each letter of a given
text is replaced by a letter with a fixed number of positions down
the alphabet. For example with a shift of 1, A would be replaced by
B, B would become C, and so on. The method is apparently named
after Julius Caesar, who apparently used it to communicate with his
officials.

Cryptography Algorithm for the Caesar


Cipher
 Thus to cipher a given text we need an integer value, known as a
shift which indicates the number of positions each letter of the
text has been moved down.
The encryption can be represented using modular arithmetic by
first transforming the letters into numbers, according to the
scheme, A = 0, B = 1,…, Z = 25. Encryption of a letter by a
shift n can be described mathematically as.
 For example, if the shift is 3, then the letter A would be replaced
by the letter D, B would become E, C would become F, and so on.
The alphabet is wrapped around so that after Z, it starts back at
A.
 Here is an example of how to use the Caesar cipher to encrypt
the message “HELLO” with a shift of 3:

1. Write down the plaintext message: HELLO


2. Choose a shift value. In this case, we will use a shift of 3.
3. Replace each letter in the plaintext message with the letter that
is three positions to the right in the alphabet.
H becomes K (shift 3 from H)
E becomes H (shift 3 from E)
L becomes O (shift 3 from L)
L becomes O (shift 3 from L)
O becomes R (shift 3 from O)
4.The encrypted message is now “KHOOR”.

 To decrypt the message, you simply need to shift each letter back
by the same number of positions. In this case, you would shift
each letter in “KHOOR” back by 3 positions to get the original
message, “HELLO”.

En(x)=(x+n)mod 26 En(x)=(x+n)mod 26
(Encryption Phase with shift n)
Dn(x)=(x−n)mod 26 Dn(x)=(x−n)mod 26
(Decryption Phase with shift n)
Examples :
Text : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Shift: 23
Cipher: XYZABCDEFGHIJKLMNOPQRSTUVW

Text : ATTACKATONCE
Shift: 4
Cipher: EXXEGOEXSRGI
Advantages
 Easy to implement and use thus, making suitable for beginners to
learn about encryption.
 Can be physically implemented, such as with a set of rotating
disks or a set of cards, known as a scytale, which can be useful in
certain situations.
 Requires only a small set of pre-shared information.
 Can be modified easily to create a more secure variant, such as
by using a multiple shift values or keywords.
Disadvantages
 It is not secure against modern decryption methods.
 Vulnerable to known-plaintext attacks, where an attacker has
access to both the encrypted and unencrypted versions of the
same messages.
 The small number of possible keys means that an attacker can
easily try all possible keys until the correct one is found, making it
vulnerable to a brute force attack.
 It is not suitable for long text encryption as it would be easy to
crack.
 It is not suitable for secure communication as it is easily broken.
 Does not provide confidentiality, integrity, and authenticity in a
message.
Features of Caesar Cipher
1. Substitution cipher: The Caesar cipher is a type of substitution
cipher, where each letter in the plaintext is replaced by a letter
some fixed number of positions down the alphabet.
2. Fixed key: The Caesar cipher uses a fixed key, which is the
number of positions by which the letters are shifted. This key is
known to both the sender and the receiver.
3. Symmetric encryption: The Caesar cipher is a symmetric
encryption technique, meaning that the same key is used for both
encryption and decryption.
4. Limited keyspace: The Caesar cipher has a very limited
keyspace of only 26 possible keys, as there are only 26 letters in
the English alphabet.
5. Vulnerable to brute force attacks: The Caesar cipher is
vulnerable to brute force attacks, as there are only 26 possible
keys to try.
6. Easy to implement: The Caesar cipher is very easy to
implement and requires only simple arithmetic operations,
making it a popular choice for simple encryption tasks.
Rules for the Caesar Cipher
1. Choose a number between 1 and 25. This will be your “shift”
value.
2. Write down the letters of the alphabet in order, from A to Z.
3. Shift each letter of the alphabet by the “shift” value. For example,
if the shift value is 3, A would become D, B would become E, C
would become F, and so on.
4. Encrypt your message by replacing each letter with the
corresponding shifted letter. For example, if the shift value is 3,
the word “hello” would become “khoor”.
5. To decrypt the message, simply reverse the process by shifting
each letter back by the same amount. For example, if the shift
value is 3, the encrypted message “khoor” would become “hello”.
Algorithm for Caesar Cipher

Input:
1. Choose a shift value between 1 and 25.
2. Write down the alphabet in order from A to Z.
3. Create a new alphabet by shifting each letter of the original
alphabet by the shift value. For example, if the shift value is 3,
the new alphabet would be:
4. A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
DEFGHIJKLMNOPQRSTUVWXYZABC
5. Replace each letter of the message with the corresponding letter
from the new alphabet. For example, if the shift value is 3, the
word “hello” would become “khoor”.
6. To decrypt the message, shift each letter back by the same
amount. For example, if the shift value is 3, the encrypted
message “khoor” would become “hello”.

Procedure:
 Traverse the given text one character at a time .
 For each character, transform the given character as per the rule,
depending on whether we’re encrypting or decrypting the text.
 Return the new string generated.

// A C++ program to illustrate Caesar Cipher Technique


#include <iostream>
using namespace std;

// This function receives text and shift and


// returns the encrypted text
string encrypt(string text, int s)
{
string result = "";

// traverse text
for (int i = 0; i < text.length(); i++) {
// apply transformation to each character
// Encrypt Uppercase letters
if (isupper(text[i]))
result += char(int(text[i] + s - 65) % 26 + 65);

// Encrypt Lowercase letters


else
result += char(int(text[i] + s - 97) % 26 + 97);
}

// Return the resulting string


return result;
}

// Driver program to test the above function


int main()
{
string text = "ATTACKATONCE";
int s = 4;
cout << "Text : " << text;
cout << "\nShift: " << s;
cout << "\nCipher: " << encrypt(text, s);
return 0;
}

Output
Text : ATTACKATONCE
Shift: 4
Cipher: EXXEGOEXSRGI

Paython:

#A python program to illustrate Caesar Cipher Technique


def encrypt(text,s):
result = ""

# traverse text
for i in range(len(text)):
char = text[i]
# Encrypt uppercase characters
if (char.isupper()):
result += chr((ord(char) + s-65) % 26 + 65)

# Encrypt lowercase characters


else:
result += chr((ord(char) + s - 97) % 26 + 97)

return result

#check the above function


text = "ATTACKATONCE"
s = 4
print ("Text : " + text)
print ("Shift : " + str(s))
print ("Cipher: " + encrypt(text,s))

Output
Text : ATTACKATONCE
Shift: 4
Cipher: EXXEGOEXSRGI

What is the Caesar cipher in cryptography?

The Caesar Cipher, used by Julius Caesar around 58 BC, is a method that
scrambles a message by shifting its letters. For example, shifting ‘A’ by three
positions makes it ‘D’. To read the message, the receiver reverses this shift.
Later, an Arab mathematician cracked the Caesar Cipher by analyzing how
often each letter appears, which helped him figure out the pattern and
decode the message.

What is an example of decryption in Caesar cipher?


An example of decryption in the Caesar cipher is decrypting the message
KHOOR. If the original shift used to encrypt the message was 3, you would
reverse this by shifting each letter back by 3 places in the alphabet. Thus, K
shifts to H, H to E, O to L, and R to O, revealing the decrypted message:
HELLO.

What are keys in Caesar cipher?

In the Caesar cipher, the key is a letter that shows how many places to shift
each letter in the message. For example, a key D means “shift 3 places,” and
a key M means “shift 12 places.” A key A means “do not shift,” and a key Z
means either “shift 25 places” or “shift one place backwards.”

Hill Cipher
Last Updated : 21 Jul, 2021



Hill cipher is a polygraphic substitution cipher based on linear


algebra.Each letter is represented by a number modulo 26. Often
the simple scheme A = 0, B = 1, …, Z = 25 is used, but this is not an
essential feature of the cipher. To encrypt a message, each block of
n letters (considered as an n-component vector) is multiplied by an
invertible n × n matrix, against modulus 26. To decrypt the
message, each block is multiplied by the inverse of the matrix used
for encryption.
The matrix used for encryption is the cipher key, and it should be
chosen randomly from the set of invertible n × n matrices (modulo
26).
Examples:

Input : Plaintext: ACT


Key: GYBNQKURP
Output : Ciphertext: POH

Input : Plaintext: GFG


Key: HILLMAGIC
Output : Ciphertext: SWK

Encryption
We have to encrypt the message ‘ACT’ (n=3).The key is
‘GYBNQKURP’ which can be written as the nxn matrix:

The message ‘ACT’ is written as vector:


The enciphered vector is given as:

which corresponds to ciphertext of ‘POH’

Decryption
To decrypt the message, we turn the ciphertext back into a vector,
then simply multiply by the inverse matrix of the key matrix
(IFKVIVVMI in letters).The inverse of the matrix used in the previous
example is:
For the previous Ciphertext ‘POH’:

which gives us back ‘ACT’.


Assume that all the alphabets are in upper case.
Below is the implementation of the above idea for n=3.

Hill Cipher
Last Updated : 21 Jul, 2021



Hill cipher is a polygraphic substitution cipher based on linear


algebra.Each letter is represented by a number modulo 26. Often
the simple scheme A = 0, B = 1, …, Z = 25 is used, but this is not an
essential feature of the cipher. To encrypt a message, each block of
n letters (considered as an n-component vector) is multiplied by an
invertible n × n matrix, against modulus 26. To decrypt the
message, each block is multiplied by the inverse of the matrix used
for encryption.
The matrix used for encryption is the cipher key, and it should be
chosen randomly from the set of invertible n × n matrices (modulo
26).
Examples:

Input : Plaintext: ACT


Key: GYBNQKURP
Output : Ciphertext: POH
Input : Plaintext: GFG
Key: HILLMAGIC
Output : Ciphertext: SWK
Encryption
We have to encrypt the message ‘ACT’ (n=3).The key is
‘GYBNQKURP’ which can be written as the nxn matrix:

The message ‘ACT’ is written as vector:

The enciphered vector is given as:


which corresponds to ciphertext of ‘POH’
Decryption
To decrypt the message, we turn the ciphertext back into a vector,
then simply multiply by the inverse matrix of the key matrix
(IFKVIVVMI in letters).The inverse of the matrix used in the previous
example is:

For the previous Ciphertext ‘POH’:

 which gives us back ‘ACT’.


Assume that all the alphabets are in upper case.
Below is the implementation of the above idea for n=3.

# Python3 code to implement Hill Cipher

keyMatrix = [[0] * 3 for i in range(3)]

# Generate vector for the message

messageVector = [[0] for i in range(3)]

# Generate vector for the cipher

cipherMatrix = [[0] for i in range(3)]

# Following function generates the

# key matrix for the key string

def getKeyMatrix(key):

k =0

for i in range(3):

for j in range(3):

keyMatrix[i][j] = ord(key[k]) % 65

k += 1

# Following function encrypts the message

def encrypt(messageVector):

for i in range(3):

for j in range(1):
cipherMatrix[i][j] = 0

for x in range(3):

cipherMatrix[i][j] += (keyMatrix[i][x] *

messageVector[x][j])

cipherMatrix[i][j] = cipherMatrix[i][j] % 26

def HillCipher(message, key):

# Get key matrix from the key string

getKeyMatrix(key)

# Generate vector for the message

for i in range(3):

messageVector[i][0] = ord(message[i]) % 65

# Following function generates

# the encrypted vector

encrypt(messageVector)

# Generate the encrypted text

# from the encrypted vector

CipherText = []

for i in range(3):

CipherText.append(chr(cipherMatrix[i][0] + 65))
# Finally print the ciphertext

print("Ciphertext: ", "".join(CipherText))

# Driver Code

def main():

# Get the message to

# be encrypted

message = "ACT"

# Get the key

key = "GYBNQKURP"

HillCipher(message, key)

if __name__ == "__main__":

main()

Output:

Ciphertext: POH

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy