Cryptography Module 1 - Part 2 Notes
Cryptography Module 1 - Part 2 Notes
Cryptography Module 1 - Part 2 Notes
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
Caesar Cipher
Monoalphabetic Ciphers
Playfair Cipher
Hill Cipher
Polyalphabetic Ciphers
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,
Problem: Use the Caesar cipher to encrypt and decrypt the message "HELLO," and the key (shift)
value of this message is 15.
Encryption
En (x) = (x + n) mod 26
Decryption
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
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:
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
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.
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.
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.
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.
Hill Cipher
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.
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.
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.
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.
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:
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.
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.