Cryptography Module 1 - Part 2 Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Techniques Used in Symmetric Key Cryptography

1. Substitution Techniques

2. Transposition Techniques

Substitution Techniques

The symmetric key cryptographic method employs one secret key for the operations of

encryption and decryption. Substitution techniques provide two significant approaches, wherein

elements (letters, characters) from the plaintext message are replaced with new elements

according to the rules based on the secret key.

 Caesar Cipher

 Monoalphabetic Ciphers

 Playfair Cipher

 Hill Cipher

 Polyalphabetic Ciphers

 One-Time Pad (OTP)


 Caesar Cipher Technique
 The Caesar cipher is the simplest and oldest method of cryptography. The Caesar cipher
method is based on a mono-alphabetic cipher and is also called a shift cipher or additive
cipher.
 The Caesar cipher is a kind of replacement (substitution) cipher, where all letter of plain
text is replaced by another letter.

Let's take an example to understand the Caesar cipher, suppose we are shifting with 1, then A
will be replaced by B, B will be replaced by C, C will be replaced by D, D will be replaced by
C, and this process continues until the entire plain text is finished.

 Caesar cipher is a weak method of cryptography. It can be easily hacked. It means the
message encrypted by this method can be easily decrypted.
 Plaintext: It is a simple message written by the user.
 Cipher text: It is an encrypted message after applying some technique.
 The formula of encryption is:
 En (x) = (x + n) mod 26
 The formula of decryption is:
 Dn (x) = (x - n) mod 26
 If any case (Dn) value becomes negative (-ve), in this case, we will add 26 in the
negative value.
 Where,

E denotes the encryption


D denotes the decryption
x denotes the letters value
n denotes the key value (shift value)

Problem: Use the Caesar cipher to encrypt and decrypt the message "HELLO," and the key (shift)
value of this message is 15.

Encryption

We apply encryption formulas by character, based on alphabetical order.

The formula of encryption is:

En (x) = (x + n) mod 26

Plaintext: H → 07 En: (07 + 15) mod 26 Ciphertext: 22 → W

Plaintext: E → 04 En: (04 + 15) mod 26 Ciphertext: 19 → T


Plaintext: L → 11 En: (11 + 15) mod 26 Ciphertext: 00 → A

Plaintext: L → 11 En: (11 + 15) mod 26 Ciphertext: 00 → A

Plaintext: O → 14 En: (14 + 15) mod 26 Ciphertext: 03 → D

The encrypted message of this plain text is "WTAAD".

Decryption

We apply decryption formulas by character, based on alphabetical order.

The formula of decryption is:

Dn (x) = (xi - n) mod 26

Ciphertext: W → 22 Dn: (22 - 15) mod 26 Plaintext: 07 → H

Ciphertext: T → 19 Dn: (19 - 15) mod 26 Plaintext: 04 → E

Ciphertext: A → 00 Dn: (00 - 15) mod 26 Plaintext: 11 → L

Ciphertext: A → 00 Dn: (00 - 15) mod 26 Plaintext: 11 → L

Ciphertext: D → 03 Dn: (03 - 15) mod 26 Plaintext: 14 → O

The decrypted message is "HELLO".

Note: If any case (Dn) value becomes negative (-ve), in this case, we will add 26 in the negative
value. Like, the third letter of the ciphertext.
Dn = (00 - 15) mod 26
= -15
The value of dn is negative, so 26 will be added to it.
= -15 + 26
= 11
Advantages of Caesar cipher

Its benefits are as follows: -


1. It is very easy to implement.
2. This method is the simplest method of cryptography.
3. Only one short key is used in its entire process.
4. If a system does not use complex coding techniques, it is the best method for it.
5. It requires only a few computing resources.

Disadvantages of Caesar cipher

Its disadvantages are as follows: -

1. It can be easily hacked. It means the message encrypted by this method can be easily
decrypted.
2. It provides very little security.
3. By looking at the pattern of letters in it, the entire message can be decrypted.

Monoalphabetic Cipher
 It is a part of the substitution technique in which a single cipher alphabet is used per
message (mapping is done from plain alphabet to cipher alphabet).
 Monoalphabetic cipher converts plain text into cipher text and re-convert a cipher text to
plain text. Monoalphabetic Cipher eliminates the brute-force techniques for cryptanalysis.
 Moreover, the cipher line can be a permutation of the 26 alphabetic characters.
How Does Monoalphabetic Cipher Work?
Let us understand how this cipher technique works with an example, let us suppose the mapping
of plaintext using the table below.
0 1 2 3 4 5 6 7 8 9 10 11 12

A B C D E F G H I J K L M

13 14 15 16 17 18 19 20 21 22 23 24 25

N O P Q R S T U V W X Y Z
Example Input 1(Plain-text)– GFG
 Explanation: In Monoalphabetic cipher, the mapping is done randomly and the difference
between the letters is not uniform. Here, the word is mapped to S (G->S), F is mapped to
R(F->R) and G was already mapped to S so we cannot change it (G->S).
 Example Output 1(Cipher-text)– SRS
Example Input 2 (Cipher-text) – GZGEWVGRNCP
 Explanation:

table for Occurrences of the alphabet


 Using the table, use the alphabet which has occurred most times. So we see, G is used most
so we replace G with E (G->E) and then V->T, R->P, N->L, C->A, Z->X, E->C, and W->U.
Thus, we found the plain text.
 Example Output 2(Plain-text) – EXECUTE
Advantages of Monoalphabetic Cipher
 Better Security than Caesar Cipher.
 Provides Encryption and Decryption to data.
 Monoalphabetic Cipher maintains a frequency of letters.

Disadvantages of Monoalphabetic Cipher


 Monoalphabetic ciphers are easy to break because they reflect the frequency data of the
original alphabet.
 Prone to guessing attack using the English letters frequency of occurrence of letters.
 The English Language is used so the nature of plain text is known.
 Less secure than a polyalphabetic cipher.

Conclusion :
Monoalphabetic cipher is a better cipher technique than Caesar cipher. Since the monoalphabetic
cipher is easy to guess using the English letter, a countermeasure is to provide multiple substitutes
known as homophones for a single letter.

Playfair Cipher

 Playfair cipher is an encryption algorithm to encrypt or encode a message. It is the same as


a traditional cipher. The only difference is that it encrypts a digraph (a pair of two letters)
instead of a single letter.
 It initially creates a key-table of 5*5 matrix. The matrix contains alphabets that act as the
key for encryption of the plaintext. Note that any alphabet should not be repeated. Another
point to note that there are 26 alphabets and we have only 25 blocks to put a letter inside
it. Therefore, one letter is excess so, a letter will be omitted (usually J) from the matrix.
Nevertheless, the plaintext contains J, then J is replaced by I. It means treat I and J as the
same letter, accordingly.

Since Playfair cipher encrypts the message digraph by digraph. Therefore, the Playfair cipher is
an example of a digraph substitution cipher.
Playfair Cipher Encryption Rules

1. First, split the plaintext into digraphs (pair of two letters). If the plaintext has the odd number
of letters, append the letter Z at the end of the plaintext. It makes the plaintext of even For
example, the plaintext MANGO has five letters. So, it is not possible to make a digraph. Since,
we will append a letter Z at the end of the plaintext, i.e. MANGOZ.

2. After that, break the plaintext into digraphs (pair of two letters). If any letter appears twice (side
by side), put X at the place of the second occurrence. Suppose, the plaintext
is COMMUNICATE then its digraph becomes CO MX MU NI CA TE. Similarly, the digraph
for the plaintext JAZZ will be JA ZX ZX, and for plaintext GREET, the digraph will be GR EX
ET.

3. To determine the cipher (encryption) text, first, build a 5*5 key-matrix or key-table and filled it
with the letters of alphabets, as directed below:

o Fill the first row (left to right) with the letters of the given keyword (ATHENS). If the
keyword has duplicate letters (if any) avoid them. It means a letter will be considered only
once. After that, fill the remaining letters in alphabetical order. Let's create a 5*5 key-
matrix for the keyword ATHENS.

Note that in the above matrix any letter is not repeated. The letters in the first row (in green color)
represent the keyword and the remaining letters sets in alphabetical order.

4. There may be the following three conditions:

i) If a pair of letters (digraph) appears in the same row


In this case, replace each letter of the digraph with the letters immediately to their right. If there is
no letter to the right, consider the first letter of the same row as the right letter. Suppose, Z is a
letter whose right letter is required, in such case, T will be right to Z.

ii) If a pair of letters (digraph) appears in the same column

In this case, replace each letter of the digraph with the letters immediately below them. If there is
no letter below, wrap around to the top of the same column. Suppose, W is a letter whose below
letter is required, in such case, V will be below W.
iii) If a pair of letters (digraph) appears in a different row and different column

In this case, select a 3*3 matrix from a 5*5 matrix such that pair of letters appear in the 3*3 matrix.
Since they occupy two opposite corners of a square within the matrix. The other corner will be a
cipher for the given digraph.

In other words, we can also say that intersection of H and Y will be the cipher for the first letter
and

Suppose, a digraph is HY and we have to find a cipher for it. We observe that both H and Y are
placed in different rows and different columns. In such cases, we have to select a 3*3 matrix in
such a way that both H and Y appear in the 3*3 matrix (highlighted with yellow color). Now, we
will consider only the selected matrix to find the cipher.
Now to find the cipher for HY, we will consider the diagonal opposite to HY, i.e. LU. Therefore,
the cipher for H will be L, and the cipher for Y will be U.

Playfair Cipher Decryption

The decryption procedure is the same as encryption but the steps are applied in reverse order. For
decryption cipher is symmetric (move left along rows and up along columns). The receiver of the
plain text has the same key and can create the same key-table that is used to decrypt the message.
Let's see an example of Playfair cipher.

Example of Playfair Cipher

Suppose, the plaintext is COMMUNICATION and the key that we will use to encipher the
plaintext is COMPUTER. The key can be any word or phrase. Let's encipher the
message COMMUNICATION.

1. First, split the plaintext into digraph (by rule 2) i.e. CO MX MU NI CA TE.

2. Construct a 5*5 key-matrix (by rule 3). In our case, the key is COMPUTER.

3. Now, we will traverse in key-matrix pair by pair and find the corresponding encipher for the
pair.

o The first digraph is CO. The pair appears in the same row. By using Rule 4(i) CO gets
encipher into OM.
o The second digraph is MX. The pair appears in the same column. By using Rule 4(ii)
MX gets encipher into RM.
o The third digraph is MU. The pair appears in the same row. By using Rule 4(i) MU gets
encipher into PC.
o The fourth digraph is NI. The pair appears in different rows and different columns. By
using Rule 4(iii) NI gets encipher into SG.
o The fifth digraph is CA. The pair appears in different rows and different columns. By
using Rule 4(iii) CA gets encipher into PT.
o The sixth digraph is TE. The pair appears in the same row. By using Rule 4(i) TE gets
encipher into ER.

Therefore, the plaintext COMMUNICATE gets encipher (encrypted) into OMRMPCSGPTER.


Advantages of Playfair Cipher
1. Diverse ciphertext if we scrutinize the Algorithm, we can notice at every Stage we are
getting diverse ciphertext, thus more trouble to cryptanalyst.
2. Brute force attack does not affect it.
3. Cryptanalyze (the process of decoding cipher without knowing key) is not possible.
4. Overcomes the limitation of simple Playfair square cipher.
5. Easy to perform the substitution.
Limitations of Playfair Cipher

The limitations of the Playfair cipher are as follows:

o Only 25 alphabets are supported.


o It does not support numeric characters.
o Only either upper cases or lower cases are supported.
o The use of special characters (such as blank space, newline, punctuations, etc.) is
prohibited.
o It does not support other languages, except English.
o Encryption of media files is also not supported.

Hill Cipher

 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).
Encryption
To encrypt the text using hill cipher, we need to perform the following operation.

1. E(K, P) = (K * P) mod 26

Where K is the key matrix and P is plain text in vector form. Matrix multiplication of K and P
generates the encrypted ciphertext.

Steps For Encryption

Step 1: Let's say our key text (2x2) is DCDF. Convert this key using a substitution scheme into a
2x2 key matrix as shown below:
Step 2: Now, we will convert our plain text into vector form. Since the key matrix is 2x2, the
vector must be 2x1 for matrix multiplication. (Suppose the key matrix is 3x3, a vector will be a
3x1 matrix.)

In our case, plain text is TEXT that is four letters long word; thus we can put in a 2x1 vector and
then substitute as:

Step 3: Multiply the key matrix with each 2x1 plain text vector, and take the modulo of result (2x1
vectors) by 26. Then concatenate the results, and we get the encrypted or ciphertext as RGWL.

Decryption

To encrypt the text using hill cipher, we need to perform the following operation.

1. D(K, C) = (K-1 * C) mod 26


Where K is the key matrix and C is the ciphertext in vector form. Matrix multiplication of inverse
of key matrix K and ciphertext C generates the decrypted plain text.

Steps For Decryption

Step 1: Calculate the inverse of the key matrix. First, we need to find the determinant of the key
matrix (must be between 0-25). Here the Extended Euclidean algorithm is used to get modulo
multiplicative inverse of key matrix determinant

Step 2: Now, we multiply the 2x1 blocks of ciphertext and the inverse of the key matrix. The
resultant block after concatenation is the plain text that we have encrypted i.e., TEXT.

One Time Pad

 Algorithm is the improvement of the Vernam Cipher


 It is the only available algorithm that is unbreakable(completely secure).
 It is a method of encrypting alphabetic plain text.
 It is one of the Substitution techniques which converts plain text into ciphertext.
In this mechanism, we assign a number to each character of the Plain-Text.
The two requirements for the One-Time pad are
 The key should be randomly generated as long as the size of the message.
 The key is to be used to encrypt and decrypt a single message, and then it is discarded.
So encrypting every new message requires a new key of the same length as the new message in
one-time pad.
The ciphertext generated by the One-Time pad is random, so it does not have any statistical
relation with the plain text.
The assignment is as follows:

A B C D E F G H I J

0 1 2 3 4 5 6 7 8 9

K L M N O P Q R S T

10 11 12 13 14 15 16 17 18 19

U V W X Y Z

20 21 22 23 24 25

The relation between the key and plain text: In this algorithm, the length of the key should
be equal to that of plain text.
Examples:
1. Input: Message = HELLO, Key = MONEY Output: Cipher – TSYPM,
Message – HELLO Explanation:
Part 1: Plain text to Ciphertext
Plain text — H E L L O ?
7 4 11 11 14
Key — M O N E Y ?
12 14 13 4 24
Plain text + key ?
19 18 24 15 38 ? 19 18 24 15 12 (= 38 – 26)
Cipher Text ? T S Y P M
Part 2: Ciphertext to Message
Cipher Text — T S Y P M ?
19 18 24 15 12
Key — M O N E Y?
12 14 13 4 24
Cipher text + key ?
7 4 11 11 -12 ? 7 4 11 11 14
Message : H E L L O
Advantages (Security) of One-Time Pad
 If any way cryptanalyst finds these two keys using which two plaintext are produced but if
the key was produced randomly, then the cryptanalyst cannot find which key is more likely
than the other. In fact, for any plaintext as the size of ciphertext, a key exists that produces
that plaintext.
 So if a cryptanalyst tries the brute force attack(try using all possible keys), he would end up
with many legitimate plaintexts, with no way of knowing which plaintext is legitimate.
Therefore, the code is unbreakable.
 The security of the one-time pad entirely depends on the randomness of the key.
 One-Time Pad is the only algorithm that is truly unbreakable and can be used for low-
bandwidth channels requiring very high security(ex. for military uses).

Disadvantages

 There is the practical problem of making large quantities of random keys. Any heavily used
system might require millions of random characters on a regular basis.
 For every message to be sent, a key of equal length is needed by both sender and receiver.
Thus, a mammoth key distribution problem exists.

Transposition Cipher Technique


The Transposition Cipher Technique is an encryption method used to encrypt a message or
information. This encryption method is done by playing with the position of letters of the plain
text. The positions of the characters present in the plaintext are rearranged or shifted to form the
ciphertext. It makes use of some kind of permutation function to achieve the encryption purpose.
It is very easy to use and so simple to implement.
Types of Transposition Cipher Techniques
There are three types of transposition cipher techniques
 Rail Fence Transposition Cipher
 Row Column Transposition Cipher
Rail Fence Transposition Cipher
 Rail Fence Transposition cipher technique is the simplest transposition cipher technique.
 It is also termed as a zigzag cipher. It gets it’s name from the way through which it
performs encryption of plain text.

The steps to get cipher text with the help of the Rail Fence Transposition cipher technique are
follows:-
Technique of Rail Fence Transposition Cipher
Example: The plain text is “Hello Krishna”
Now, we will write this plain text in the diagonal form:

Rail Fence Transposition Cipher

Now, following the second step we get our cipher text


Cipher Text = “hlorsnelkiha”

Steganography
Steganography is a method in which a secret message is hidden in a cover media.
Steganography means covered writing. Steganography is the idea of preventing secret
information by creating suspicion. Steganography is less popular than Cryptography.
In steganography, the structure of data is not usually altered.

The forms of steganography are:


 Text
 Audio
 Video
 Images
 Network or Protocol
Difference between Steganography and Cryptography
Basis Steganography Cryptography

Definitio Steganography means covered


Cryptography means secret writing.
n writing.

popularit Steganography is less popular than While cryptography is more popular


y Cryptography. than Steganography.

Attack The attack’s name in Steganography In cryptography, the Attack’s name


Name is Steganalysis. is Cryptanalysis.

Cryptography
Security Steganography supports Confidentiality and Authen
Principle supports Confidentiality and Authen tication security principles as well
s tication security principles. as Data integrity and Non-
repudiation.

Mathema
In steganography, not many Cryptography involves the use of
tical
mathematical transformations are number theory, mathematics, etc. to
Involvem
involved. modify data
ent

Informati
In Steganography the information is In cryptography, the information is
on
hidden. transformed.
Handling

Informati
on The hidden information is not visible. Transformed information is visible.
Visibility
Basis Steganography Cryptography

Cryptography Provides
Security Steganography Provides
Confidentiality, Integrity, Non-
Services Confidentiality only.
repudiation.

Algorith Steganography doesn’t have specific Cryptography has Various recognized


ms algorithms. and approved algorithms.

The goal of steganography is to make


The main goal of cryptography is to
the information invisible to anyone
Goal keep the contents of the message
who doesn’t know where to look or
secret from unauthorized access.
what to look for

You might also like