KEMBAR78
Caesar Cipher | PDF | Cipher | Encryption
0% found this document useful (0 votes)
383 views12 pages

Caesar Cipher

The document summarizes classical encryption techniques, including the Caesar cipher, Playfair cipher, and Vigenere cipher. The Caesar cipher involves shifting each letter by a fixed number, such as shifting each letter forward by 3. The Playfair cipher encrypts pairs of letters (digraphs) based on their position in a 5x5 grid keyed with a word. The Vigenere cipher uses a table of alphabets to encrypt letters based on a repeating keyword.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
383 views12 pages

Caesar Cipher

The document summarizes classical encryption techniques, including the Caesar cipher, Playfair cipher, and Vigenere cipher. The Caesar cipher involves shifting each letter by a fixed number, such as shifting each letter forward by 3. The Playfair cipher encrypts pairs of letters (digraphs) based on their position in a 5x5 grid keyed with a word. The Vigenere cipher uses a table of alphabets to encrypt letters based on a repeating keyword.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CLASSICAL ENCRYPTION TECHNIQUES

I. Substitution techniques
A substitution technique is one in which the letters of plaintext are replaced by other letters or
by numbers or symbols. If the plaintext is viewed as a sequence of bits, then substitution
involves replacing plaintext bit patterns with cipher text bit patterns.

1. Caesar Cipher

The Caesar Cipher technique is one of the earliest and simplest methods of encryption
technique. 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.

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.

𝐸𝑛 (𝑥) = (𝑥 + 𝑛)𝑚𝑜𝑑26
(Encryption Phase with shift n)

𝐷𝑛 (𝑥) = (𝑥 − 𝑛)𝑚𝑜𝑑26
(Decryption Phase with shift n)

Examples :

Text : ABCDEFGHIJKLMNOPQRSTUVWXYZ
Shift: 23
Cipher: XYZABCDEFGHIJKLMNOPQRSTUVW

Text : ATTACKATONCE
Shift: 4
Cipher: EXXEGOEXSRGI
Advantages:

p. 1
 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.

Algorithm for Caesar Cipher:


Input:

1. A String of lower case letters, called Text.


2. An Integer between 0-25 denoting the required shift.

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.

2. Playfair Cipher
The Playfair cipher was the first practical digraph substitution cipher. The scheme was invented
in 1854 by Charles Wheatstone but was named after Lord Playfair who promoted the use of the
cipher. In playfair cipher unlike traditional cipher we encrypt a pair of alphabets(digraphs)
instead of a single alphabet.
It was used for tactical purposes by British forces in the Second Boer War and in World War I
and for the same purpose by the Australians during World War II. This was because Playfair is
reasonably fast to use and requires no special equipment.

Encryption Technique

For the encryption process let us consider the following example:

p. 2
The Playfair Cipher Encryption Algorithm:
The Algorithm consists of 2 steps:

 Generate the key Square(5×5):

 The key square is a 5×5 grid of alphabets that acts as the key for encrypting the plaintext.
Each of the 25 alphabets must be unique and one letter of the alphabet (usually J) is
omitted from the table (as the table can hold only 25 alphabets). If the plaintext contains
J, then it is replaced by I.
 The initial alphabets in the key square are the unique alphabets of the key in the order
in which they appear followed by the remaining letters of the alphabet in order.

 Algorithm to encrypt the plain text: The plaintext is split into pairs of two letters (digraphs).
If there is an odd number of letters, a Z is added to the last letter.
For example:
PlainText: "instruments"
After Split: 'in' 'st' 'ru' 'me' 'nt' 'sz'

1. Pair cannot be made with same letter. Break the letter in single and add a bogus letter to the
previous letter.

Plain Text: “hello”

After Split: ‘he’ ‘lx’ ‘lo’

Here ‘x’ is the bogus letter.

2. If the letter is standing alone in the process of pairing, then add an extra bogus letter with
the alone letter

Plain Text: “helloe”

AfterSplit: ‘he’ ‘lx’ ‘lo’ ‘ez’

Here ‘z’ is the bogus letter.

Rules for Encryption:

 If both the letters are in the same column: Take the letter below each one (going
back to the top if at the bottom).
For example:
Diagraph: "me"
Encrypted Text: cl

p. 3
Encryption:
m -> c
e -> l

 If both the letters are in the same row: Take the letter to the right of each one (going
back to the leftmost if at the rightmost position).
For example:
Diagraph: "st"
Encrypted Text: tl
Encryption:
s -> t
t -> l

 If neither of the above rules is true: Form a rectangle with the two letters and take the letters
on the horizontal opposite corner of the rectangle.
For example:
Diagraph: "nt"
Encrypted Text: rq
Encryption:
n -> r
t -> q

p. 4
For example:
Plain Text: "instrumentsz"
Encrypted Text: gatlmzclrqtx
Encryption:

i -> g
n -> a
s -> t
t -> l
r -> m
u -> z
m -> c
e -> l
n -> r
t -> q
s -> t
z -> x

Decryption Technique

Decrypting the Playfair cipher is as simple as doing the same process in reverse. The receiver
has the same key and can create the same key table, and then decrypt any messages made using
that key.

The Playfair Cipher Decryption Algorithm:


The Algorithm consists of 2 steps:

1. Generate the key Square(5×5) at the receiver’s end:


o The key square is a 5×5 grid of alphabets that acts as the key for encrypting the
plaintext. Each of the 25 alphabets must be unique and one letter of the
alphabet (usually J) is omitted from the table (as the table can hold only 25
alphabets). If the plaintext contains J, then it is replaced by I.

p. 5
o The initial alphabets in the key square are the unique alphabets of the key in
the order in which they appear followed by the remaining letters of the
alphabet in order.

2. Algorithm to decrypt the ciphertext: The ciphertext is split into pairs of two letters
(digraphs).

Note: The ciphertext always have even number of characters.

1. For example:

CipherText: "gatlmzclrqtx"
After Split: 'ga' 'tl' 'mz' 'cl' 'rq' 'tx'

1. Rules for Decryption:


o If both the letters are in the same column: Take the letter above each one
(going back to the bottom if at the top).
For example:
Diagraph: "cl"
Decrypted Text: me
Decryption:
c -> m
l -> e

 If both the letters are in the same row: Take the letter to the left of each one (going
back to the rightmost if at the leftmost position).
For example:
Diagraph: "tl"
Decrypted Text: st
Decryption:
t -> s
l -> t

p. 6
 If neither of the above rules is true: Form a rectangle with the two letters and take
the letters on the horizontal opposite corner of the rectangle.
For example:
Diagraph: "rq"
Decrypted Text: nt
Decryption:
r -> n
q -> t

For example:
Plain Text: "gatlmzclrqtx"

Decrypted Text: instrumentsz


Decryption:
(red)-> (green)
ga -> in
tl -> st
mz -> ru
cl -> me
rq -> nt
tx -> sz

p. 7
Advantages and Disadvantages

 Advantages:
1. It is significantly harder to break since the frequency analysis technique used
to break simple substitution ciphers is difficult but still can be used on (25*25)
= 625 digraphs rather than 25 monographs which is difficult.

2. Frequency analysis thus requires more cipher text to crack the encryption.

 Disadvantages:
1. An interesting weakness is the fact that a digraph in the ciphertext (AB) and
it’s reverse (BA) will have corresponding plaintexts like UR and RU (and also
ciphertext UR and RU will correspond to plaintext AB and BA, i.e. the
substitution is self-inverse). That can easily be exploited with the aid of
frequency analysis, if the language of the plaintext is known.

2. Another disadvantage is that playfair cipher is a symmetric cipher thus same


key is used for both encryption and decryption.

3. Vigenère Cipher

Vigenere Cipher is a method of encrypting alphabetic text. It uses a simple form of


polyalphabetic substitution. A polyalphabetic cipher is any cipher based on substitution, using
multiple substitution alphabets. The encryption of the original text is done using the Vigenère
square or Vigenère table.

 The table consists of the alphabets written out 26 times in different rows, each alphabet
shifted cyclically to the left compared to the previous alphabet, corresponding to the 26
possible Caesar Ciphers.
 At different points in the encryption process, the cipher uses a different alphabet from
one of the rows.
 The alphabet used at each point depends on a repeating keyword.

Example:

Input: Plaintext: GEEKSFORGEEKS

p. 8
Keyword: AYUSH
Output: Ciphertext: GCYCZFMLYLEIM
For generating key, the given keyword is repeated in a circular manner
until it matches the length of the plain text.
The keyword "AYUSH" generates the key "AYUSHAYUSHAYU"
The plain text is then encrypted using the process explained below.

Encryption:

The first letter of the plaintext, G is paired with A, the first letter of the key. So use row G and
column A of the Vigenère square, namely G. Similarly, for the second letter of the plaintext,
the second letter of the key is used, the letter at row E, and column Y is C. The rest of the
plaintext is enciphered in a similar fashion.

Decryption:
Decryption is performed by going to the row in the table corresponding to the key, finding the
position of the ciphertext letter in this row, and then using the column’s label as the plaintext.
For example, in row A (from AYUSH), the ciphertext G appears in column G, which is the
first plaintext letter. Next, we go to row Y (from AYUSH), locate the ciphertext C which is
found in column E, thus E is the second plaintext letter.

An easier implementation could be to visualize Vigenère algebraically by converting [A-Z]


into numbers [0–25].

p. 9
Encryption
The plaintext(P) and key(K) are added modulo 26.
𝐸𝑖 = (𝑃𝑖 + 𝐾𝑖 ) 𝑚𝑜𝑑 26

Decryption
𝐷𝑖 = (𝐸𝑖 − 𝐾𝑖 + 26) 𝑚𝑜𝑑 26

Note: Di denotes the offset of the i-th character of the plaintext. Like offset of A is 0 and of B
is 1 and so on.

II. Transposition techniques


All the techniques examined so far involve the substitution of a cipher text symbol for a
plaintext symbol. A very different kind of mapping is achieved by performing some sort of
permutation on the plaintext letters. This technique is referred to as a transposition cipher.
Rail fence is simplest of such cipher, in which the plaintext is written down as a sequence of
diagonals and then read off as a sequence of rows.

1. Rail Fence Cipher

Given a plain-text message and a numeric key, cipher/de-cipher the given text using Rail Fence
algorithm.

The rail fence cipher (also called a zigzag cipher) is a form of transposition cipher. It derives
its name from the way in which it is encoded.

Examples:

Encryption
Input: "GeeksforGeeks "
Key = 3
Output: GsGsekfrek eoe
Decryption
Input: GsGsekfrek eoe
Key = 3
Output: "GeeksforGeeks "
Encryption
Input: "defend the east wall"
Key = 3
Output: dnhaweedtees alf tl
Decryption
Input: dnhaweedtees alf tl
Key = 3
Output: defend the east wall

Encryption
Input: "attack at once"
Key = 2
Output: atc toctaka ne
Decryption
Input: "atc toctaka ne"
Key = 2
Output : attack at once

In a transposition cipher, the order of the alphabets is re-arranged to obtain the cipher-text.

p. 10
 In the rail fence cipher, the plain-text is written downwards and diagonally on
successive rails of an imaginary fence.
 When we reach the bottom rail, we traverse upwards moving diagonally, after
reaching the top rail, the direction is changed again. Thus the alphabets of the message
are written in a zig-zag manner.
 After each alphabet has been written, the individual rows are combined to obtain the
cipher-text.

For example, if the message is “GeeksforGeeks” and the number of rails = 3 then cipher is
prepared as:

Decryption

As we’ve seen earlier, the number of columns in rail fence cipher remains equal to the length
of plain-text message. And the key corresponds to the number of rails.

 Hence, rail matrix can be constructed accordingly. Once we’ve got the matrix we can
figure-out the spots where texts should be placed (using the same way of moving
diagonally up and down alternatively ).
 Then, we fill the cipher-text row wise. After filling it, we traverse the matrix in zig-
zag manner to obtain the original text.

Implementation:
Let cipher-text = “GsGsekfrek eoe” , and Key = 3

 Number of columns in matrix = len(cipher-text) = 13


 Number of rows = key = 3

Hence original matrix will be of 3*13, now marking places with text as ‘*’ we get

* _ _ _ * _ _ _ * _ _ _ *
_ * _ * _ * _ * _ * _ *
_ _ * _ _ _ * _ _ _ * _
2. Feistel Cipher
Feistel Cipher model is a structure or a design used to develop many block ciphers such as DES
(Data Encryption Standard). Feistel cipher may have invertible, non-invertible and self-
invertible components in its design. Same encryption as well as decryption algorithm is used.
A separate key is used for each round. However same round keys are used for encryption as
well as decryption.

p. 11
Feistel cipher algorithm

 Create a list of all the Plain Text characters.

 Convert the Plain Text to Ascii and then 8-bit binary format.

 Divide the binary Plain Text string into two halves: left half (L1)and right half (R1)

 Generate a random binary keys (K1 and K2) of length equal to the half the length of the Plain
Text for the two rounds.

First Round of Encryption

 a. Generate function f1 using R1 and K1 as follows:

f1= xor(R1, K1)

 b. Now the new left half(L2) and right half(R2) after round 1 are as follows:

R2= xor(f1, L1)


L2=R1

Second Round of Encryption

 a. Generate function f2 using R2 and K2 as follows:


f2= xor(R2, K2)
 b. Now the new left half(L3) and right half(R3) after round 2 are as follows:

R3= xor(f2, L2)


L3=R2

 Concatenation of R3 to L3 is the Cipher Text


 Same algorithm is used for decryption to retrieve the Plain Text from the Cipher Text.

Examples:

Plain Text is: Hello


Cipher Text: E1!w(
Retrieved Plain Text is: b'Hello'

Plain Text is: Geeks


Cipher Text: O;Q
Retrieved Plain Text is: b'Geeks'

p. 12

You might also like