Chapter-2-Symmetric Ciphers
Chapter-2-Symmetric Ciphers
Dr Savitha G
Dr Girisha S
Dr Ashutosh B Holla
Introduction
➢What you will study:
➢Symmetric Cipher Model
➢Cryptography
➢Cryptanalysis and brute force attack
➢Substitution Techniques
➢Caesar Cipher
➢Monoalphabetic Cipher
➢Playfair Cipher
➢Hill Cipher
➢Transposition Techniques
Introduction
➢ Symmetric encryption, also referred to as conventional encryption or single-key
encryption, was the only type of encryption in use prior to the development of
public key encryption
➢ Few terms:
An original message is known as the plaintext, while the coded message is called the
ciphertext
The process of converting from plaintext to ciphertext is known as enciphering or
encryption
Restoring the plaintext from the ciphertext is deciphering or decryption
The many schemes used for encryption constitute the area of study known as
cryptography
Such a scheme is known as a cryptographic system or a cipher
Techniques used for deciphering a message without any knowledge of the enciphering
details fall into the area of cryptanalysis
The areas of cryptography and cryptanalysis together are called cryptology
Symmetric Cipher Model
✓It has few components:
➢Plain Text
➢Encryption Algorithm:
• The encryption algorithm performs various substitutions and
transformations on the plaintext
➢Secret key:
• The secret key is also input to the encryption algorithm
• The key is a value independent of the plaintext and the
algorithm
• The algorithm will produce a different output depending on the
specific key being used at the time
• The exact substitutions and transformations performed by the
algorithm depend on the key
Symmetric Cipher Model
➢Ciphertext:
• This is the scrambled message produced as output
• It depends on the plaintext and the secret key
• For a given message, two different keys will produce two
different ciphertexts
• The ciphertext is an apparently random stream of data and, as it
stands, is unintelligible
➢Decryption algorithm:
• This is essentially the encryption algorithm run in reverse
• It takes the ciphertext and the secret key and produces the
original plaintext
Symmetric Cipher Model
Symmetric Cipher Model
➢There are two requirements for secure use of
conventional encryption:
✓We need a strong encryption algorithm.
✓The opponent should be unable to decrypt ciphertext or
discover the key even if he or she is in possession of a
number of ciphertexts together with the plaintext that
produced each ciphertext.
✓Sender and receiver must have obtained copies of the
secret key in a secure fashion and must keep the key
secure. If someone can discover the key and knows the
algorithm, all communication using this key is readable
Symmetric Cipher Model
➢A source produces a message in plaintext, X = [X1, X2, …., XM]. The M
elements of X are letters in some finite alphabet
➢ For encryption, a key of the form K = [K1, K2, … , KJ] is generated
➢ With the message X and the encryption key K as input, the encryption
algorithm forms the ciphertext Y = [Y1, Y2, … , YN]. We can write this
as
Y= E(K, X)
➢ The intended receiver, in possession of the key, is able to invert the
transformation
X = D(K, Y)
➢ An opponent, observing Y but not having access to K or X, may attempt
to recover X or K or both X and K
Symmetric Cipher Model
Cryptography
Three independent dimensions:
➢The type of operations used for transforming plaintext to ciphertext:
Substitution, in which each element in the plaintext (bit, letter, group of bits or letters) is
mapped into another element
Transposition, in which elements in the plaintext are rearranged
➢ If
the letter is standing alone in the process of paring, then add extra
dummy letter
Substitution Techniques:
Playfair Cipher
➢ If
both the letters are in the same column: Take the letter below
each one
▪ Digraph: “me”
▪ Encryption: “cl”
➢ Ifboth the letters are in the same row: Take the letter to the right
of each one
▪ Digraph: “st”
▪ Encryption: “tl”
➢ Ifneither 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.
▪ Diagraph: “nt”
▪ Encryption: “rq”
Substitution Techniques: Hill
Cipher
Determinant of a matrix:
• Ex: 2x2 matrix
𝑎11 𝑎12
|𝑎 𝑎22 | = (𝑎11 × 𝑎22 - 𝑎12 × 𝑎21 )
21
𝑎22 −𝑎12
𝑎𝑑𝑗 𝐾 = −𝑎 𝑎11
21
𝑎21 𝑎23
𝐾12 = 𝑎 𝑎33 = 𝑎21 × 𝑎33 − 𝑎31 × 𝑎23
31
𝑎21 𝑎22
𝐾13 = 𝑎 𝑎32 = 𝑎21 × 𝑎32 − 𝑎22 × 𝑎31
31
…
𝑎11 𝑎12
𝐾33 = 𝑎 𝑎22 = 𝑎11 × 𝑎22 − 𝑎21 × 𝑎12
21
Substitution Techniques: Hill
Cipher
• Cofactor of a matrix: + − +
− + −
+ − +
H E L L O
7 4 11 11 14
17 17 5 17 17 5
= 7 4 11 21 18 21 𝑚𝑜𝑑26 = 11 14 23 21 18 21 𝑚𝑜𝑑26
2 2 19 2 2 19
= (17 5 16) = (7 17 6)
=RFQ =HRG
➢ “HELLOX” = “RFQHRG”
Substitution Techniques: Hill
Cipher
Decryption algorithm:
𝟏
➢ We need to find 𝑲−𝟏 = 𝒂𝒅𝒋 𝑲
𝑲
17 17 5
➢ Given K: 21 18 21
2 2 19
➢ Det K = 17(18*19-2*21)-17(21*19-2*21)+5(21*2-2*18) mod 26
=(5100-6069+30) mod 26
= (-939) mod 26 Formula: a mod b = a - b × floor(a/b)
-939 mod 26 = −939−26×⌊-939/26⌋
= 23 = −939−26×⌊−36.115⌋
= −939−26×(−37)
= −939+962
= 23
Substitution Techniques: Hill
Cipher
To find the Adj K
➢Find the minor of the matrix
➢Find the cofactor of the matrix
➢Find the transpose of the matrix
300 −313 267
➢ −357 313 −252 𝑚𝑜𝑑 26
6 0 −51
14 25 7
➢ Adj K= 7 1 8
6 0 1
Substitution Techniques: Hill
Cipher
14 25 7
−𝟏 𝟏
➢𝑲 = 7 1 8 𝑚𝑜𝑑 26
𝟐𝟑
6 0 1
➢ We need to find the multiplicative inverse of 23 mod 26 (Extended
Euclidean Algorithm)
Q A B R T1 T2 T
1 26 23 3 0 1 -1
7 23 3 2 1 -1 8
1 3 2 1 -1 8 -9
2 2 1 0 8 -9 26
1 0 -9 26
• Start with:
• T1=0,T2=1
• Compute T=T1−Q⋅T2
• T=0−1⋅1=−1
4 9 15
➢ 𝑲−𝟏 = 15 17 6
24 0 17
Substitution Techniques: Hill
Cipher
4 9 15 4 9 15
= 17 5 16 15 17 6 𝑚𝑜𝑑26 = 7 17 6 15 17 6 𝑚𝑜𝑑26
24 0 17 24 0 17
=HEL =LOX
Substitution Techniques: Hill
Cipher
• Consider the following plain text: “HELLO”
5 8
• The key is
17 3
• The Hill Algorithm:
• C=E(K,P)=P x K mod 26
• P=D(K,C)= C x 𝑲−𝟏 mod 26
𝑘11 𝑘12
• 𝑐1 𝑐2 = 𝑝1 𝑝2 𝑚𝑜𝑑 26
𝑘21 𝑘22
Substitution Techniques: Hill
Cipher
➢ The encoded plain text is:
H E L L O
7 4 11 11 14
5 8 5 8 5 8
= 74 𝑚𝑜𝑑26 = 11 11 𝑚𝑜𝑑26 = 14 23 𝑚𝑜𝑑26
17 3 17 3 17 3
➢ “HELLOX” = “ZQIRTZ”
Substitution Techniques: Hill
Cipher
Decryption algorithm:
𝟏
➢ We need to find 𝑲−𝟏 = 𝒂𝒅𝒋 𝑲
𝑲
5 8
➢ Given K:
17 3
➢ Det K = (5*3 – 8*17)mod 26
= -121mod 26
Formula: a mod b = a - b × floor(a/b)
-121 mod 26 = −121−26×⌊-121/26⌋
−121−26×⌊−4.65⌋
= −121−26×(−5)
=9
Substitution Techniques: Hill
Cipher
𝟏 5 8
➢ 𝑲−𝟏 =𝟗 𝑚𝑜𝑑 26
17 3
➢ Weneed to find the multiplicative inverse of 9 mod 26 (Extended
Euclidean Algorithm)
Q A B R T1 T2 T
2 26 9 8 0 1 -2
1 9 8 1 1 -2 3
8 8 1 0 -2 3 -26
1 0 3 -26
𝑎22 −𝑎12
𝑎𝑑𝑗 𝐾 = −𝑎 𝑎11
21
5 8
• Adjoint of K =
17 3
3 −8
• =
−17 5
Substitution Techniques: Hill
Cipher
𝟏
• We need to find 𝑲−𝟏 = 𝒂𝒅𝒋 𝑲
𝑲
3 −8
• 3* mod 26
−17 5
9 −24
• = 𝑚𝑜𝑑 26
−51 15
9 2
• 𝑲−𝟏 = =
1 15
Substitution Techniques: Hill
Cipher
9 2 9 2 9 2
= 25 16 𝑚𝑜𝑑26 = 8 17 𝑚𝑜𝑑26 = 19 25 𝑚𝑜𝑑26
1 15 1 15 1 15
• 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.
• Example:
• Let cipher-text = “MEMATRHTGPRYETEFETEOAAT” , and Key = 2
• Add the numeric form of plaintext and key text. So after adding both the values we
will get 12 7 8 32 21 31 36 29 36 25 28 35 −
• Now we have some numbers in the above outcome (shown in bold) which is greater
that 26 so we will subtract these number with 26 and then the final outcome will
be − 12 17 8 6 21 5 10 3 10 25 2 9
• So the new ciphertext will be: MRIGVFKDKZDJ.
END