Unit - 2 - Classical Cryptography-Symmetric Key Cryptography
Unit - 2 - Classical Cryptography-Symmetric Key Cryptography
Classical Cryptography
&
Symmetric Key Cryptography
Sender Recipient
Security -related Info. Security -related
Channel
Message
Message
Message
Message
Transformation Transformation
Secure
Secure
Secret Secret
Information Opponent Information
(Attacker)
1. The cost of breaking the cipher exceeds the value of the encrypted
information.
2. The time required to break the cipher exceeds the useful lifetime of the
information.
C = E(3, P) = (P + 3) mod 26
For decryption algorithm is:
P = D(3, C) = (C - 3) mod 26
C = E(3, P) = (P + 3) mod 26
Plain: 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
Cipher: d e f g h i j k l m n o p q r s t u v w x y z a b
Example:
c
Plaintext: THE QUICK BROWN FOX
Ciphertext: WKH TXLFN EURZQ IRA
Ciphertext:
uzqsovuohxmopvgpozpevsgzwszopfpesxudbmetsxaizvuephzhmdzshz
owsfpappdtsvpquzwymxuzuhsxepyepopdzszufpombzwpfupzhmdjudtm
ohmq
In our ciphertext, the most common digram is ZW, which appears
three times. So equate Z with t, W with h and P with e.
Now notice that the sequence ZWP appears in the ciphertext, and
we can translate that sequence as “the.”
Unit-2: Classical and Symmentric Key Cryptography 27
Attack on Monoalphabetic Cipher
M O N I S Encrypted Message:
A B C D E hq cz du
F G H K L
P Q R T U
V W X Y Z
Pair: UA AR BE DE XA PO PR QN XA XA NR
Plaintext: we wi lx lm ex et at th ex ex it
Plaintext: we wilxl mexet at thex exit
Plaintext: we will meet at the exit
Unit-2: Classical and Symmentric Key Cryptography 36
Playfair Cipher 6*6 Matrix Examples
5. Keyword: FRIENDS4EVER
Key: FRIENDS4V
Rules :
Enter the secret (password) which may contain numerals and alphabets.
Find out the keyword by dropping the duplicate letters of key.
Arrange the keyword in 6 X 6 matrix row-wise: left to right and then top-to-
bottom.
Fill the remaining spaces in the matrix with the rest of numerals (0-9) and
alphabets (A-Z) that were not the part of our keyword.
mod 26
C=PK mod 26
( 7
11
8
11 )( )4
23 ( 7
11
8
11 )( )
0
12
x 4 + 8 x 23 = 212 x 0 + 8 x 12 = 96
x 4 + 11 x 23 = 297 x 0 + 11 x 12 = 132
( 7
11
8
11 )( ) (
4
23
=
2 12
297 ) ( 7
11
8
11 )( ) (
0
12
=
96
132 )
= mod 26 = = mod 26 =
Ciphertext = “ELSC”
Unit-2: Classical and Symmentric Key Cryptography 41
Hill Cipher Decryption
-1
P=CK mod 26
Step 1: Find Inverse of key matrix
Step 2: Multiply the Multiplicative Inverse of the Determinant by the
Adjoin Matrix
Step 3: Multiply inverse key matrix with ciphertext matrix to obtain
plaintext matrix
[ ] [ ]
−1
a b 1 d −b
=
c d ad − cb −c a
3 X 3 inverse of matrix
−1 1
A = ∙ adjoin( A )
determinant ( A )
¿
1 11
− 11 − 1 1 ( −8
7 )
-11 mod 26 = 15
¿
1 11
15 15 ( 18
7 )
mod 26 Because, modulo for negative
number is = N- (B%N)
= 26 – (11%26)
Example-2:
A * A-1 mod C = 1 12
A = 10, C = 17 , A-1 = ?
Unit-2: Classical and Symmentric Key Cryptography 45
Step 2: Modular (Multiplicative) inverse
Determinants’ multiplicative inverse Modulo 26
Determinant 1 3 5 7 9 11 15 17 19 21 23 25
Inverse Modulo 26 1 9 21 15 3 19 7 23 11 5 17 25
¿
1
15 ( 11
15
18
7 ) mod 26
Multiplicative inverse of is 7
¿ thus , if K =
(11X%Y
7 8
11 )
= X-(X/Y)*Y
−1
then K =
25
1 ( 22
23 )
77%26 = 77-(77/26)*26
= 77-(2)*26
= 77-52
= 25
P=CK-1 mod 26
( 25
1
22
23 )( )4
11 ( 25
1
22
23 )( )
18
2
x 4 + 22 x 11 = 342 x 18 + 22 x 2 = 494
x 4 + 23 x 11 = 257 x 18 + 23 x 2 = 64
( 25
1
22
23 )( ) (
4
11
=
342
257 ) ( 7
11
8
11 )( ) (
0
12
=
494
64 )
= mod 26 = = mod 26 =
Plaintext = “EXAM”
Unit-2: Classical and Symmentric Key Cryptography 48
Hill Cipher Examples
1. Key: Hill Plaintext: short example
Ciphertext: APADJ TFTWLFJ
2. Key: ACBA Plaintext: DR GREER ROCKS (A=1, B=2,
…)
Ciphertext: FZIFTOTBXGPO
3. Key:DACB Ciphertext: SAKNOXAOJ (A=1,B=2,…)
Plaintext: WELOVEMATH
K
e
y
PT = HELLO
KEY = GMGMG
CT = NQRXU
Vigenere Cipher
Keyword : DECEPTIVE Key must be as
Key : DECEPTIVEDECEPTIVEDECEPTIVE long as plaintext
else repeat a
Plaintext : WEAREDISCOVEREDSAVEYOURSELF keyword
Ciphertext : ZICVTWQNGRZGVTWAVZHCQYGLMGJ
C =( P1 + K 1 , P 2+ K 2 , … P m + K m ) mod 26
P =( C 1 − K 1 ,C 2 − K 2 , … Cm − K m ) mod 26
I R T N G
N E N T E H O O Y
T E C L
Bit-stream Bit-stream
Key(ki) Key(ki)
Generation Generation
010101 algorithm 010101 algorithm
Ki Ki
Plaintext(pi) Ciphertext(ci) Plaintext(pi)
100101
⊕ 110000
⊕ 100101
ENCRYPTION DECRYPTION
Plaintext Ciphertext
Ciphertext Plaintext
b bits b bits
2
2
K Key (K) 1 1 0 0 0 1 1 1 1 0
P10 (K) 0 0 1 1 0 0 1 1 1 1
Shift (P10(k)) 0 1 1 0 0 1 1 1 1 0
K1 P8 (Shift (P10(k))) 1 1 1 0 1 0 0 1
P10 (K) 0 0 1 1 0 0 1 1 1 1
Shift3 (P10(k)) 1 0 0 0 1 1 1 0 1 1
P8 (Shift3 (P10(k))) 1 0 1 0 0 1 1 1
K2
K16 48 56
Round 16 Permuted choice 2 Left circular shift
32-bit swap
64
Inverse
Initial Permutation
DES Encryption
64-bit ciphertext
Algorithm
Data Encryption Standard
X
Initial Permutation
X
Encryption
K1
64 Round 1
DES 56 Ki
64 Encryption
K16
Y Round 16
Final permutation
Y
Unit-2: Classical and Symmentric Key Cryptography 89
DES Single Round
Substitution/choice
(S-box)
32
Permutation
(P)
32
XOR
𝐿𝑖 𝑅𝑖 𝐶𝑖 𝐷𝑖
DES Encryption Algorithm
1. Initial permutation: First, the 64-bit plaintext passes through an initial
permutation (IP) that rearranges the bits to produce the permuted
input.
2. The F function: This phase consisting of sixteen rounds of the same
function, which involves both permutation and substitution functions.
3. Swap: L and R swapped again at the end of the cipher, i.e., after round
16 followed by a final permutation.
4. Inverse (Final) permutation: It is the inverse of the initial permutation.
5. Subkey generation: For each of the sixteen rounds, a different subkey
(Ki) derived from main key by the combination of a left circular shift
and a permutation.
32
Permutation
(P)
32
1. The Expansion Function E
Ri-1
Main purpose: Increases diffusion
32
Since Ri-1 is a 32-bit input and Ki is
Expansion/permutation
a 48-bit key, we first need to (E table)
expand Ri-1 to 48 bits. 48
S-box 1
Example:
Input 0 1 1 0 0 1 Output 1 0 0 1
Row Column
32
Permutation
(P)
32
Unit-2: Classical and Symmentric Key Cryptography 102
Key schedule of DES
Derives 16 round keys (or K
subkeys) ki of 48 bits each from 64
key 1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1
28 28
K1 PC-2 C1 D1
48 56
28 28
LS2 LS2
LS16 LS16
28 28
K16 PC-2 C16 D16
48 56
Avalanche Effect
Desirable property of any encryption algorithm is that a change in
one bit of the plaintext or of the key should produce a change in
many bits of cipher text.
DES performs strong avalanche effect.
Although the two plaintext blocks differ only in the rightmost bit,
the ciphertext blocks differ in 29 bits.
This means that changing approximately 1.5 % of the plaintext
creates a change of approximately 45 % in the ciphertext.
Unit-2: Classical and Symmentric Key Cryptography 107
Completeness Effect
It means that each bit of cipher text needs to depend on many bit
on plaintext.
Timing Attacks
Unit-2: Classical and Symmentric Key Cryptography 109
DES Design Criteria
The design of DES was revealed by IBM in 1994. Many tests on DES have
proved that it satisfies some of the required criteria as claimed. We
briefly discuss some of these design issues.
P-Boxes (Permutation) : We have discussed the general design criteria
for S-boxes ; we only discuss the criteria selected for DES here. The
design provides confusion and diffusion of bits from each round to the
next. According to this revelation and some research, we can mention
several properties of S-boxes.
1. The entries of each row are permutations of values between 0 and 15.
2. S-boxes are nonlinear. In other words, the output is not an affine
transformation of the input.
3. If we change a single bit in the input, two or more bits will be changed
in the output.
Between two rows of S-boxes (in two subsequent rounds), there are one straight D-box (32 to 32) and one
expansion D-box (32 to 48). These two D-boxes together provide diffusion of bits. We have discussed the
general design principle of D-boxes in Chapter 5. Here we discuss only the ones applied to the D-boxes
used inside the DES function. The following criteria were implemented in the design of D-boxes to achieve
this goal:
1. Each S-box input comes from the output of a different S-box (in the previous round).
2. No input to a given S-box comes from the output from the same box (in the previous round).
3. The four outputs from each S-box go to six different S-boxes (in the next round).
4. No two output bits from an S-box go to the same S-box (in the next round).
5. If we number the eight S-boxes, S1, S2, …, S8, a. An output of Sj−2 goes to one of the fi rst two bits of Sj
(in the next round). b. An output bit from Sj −1 goes to one of the last two bits of Sj (in the next round). c.
An output of Sj +1 goes to one of the two middle bits of Sj (in the next round).
6. For each S-box, the two output bits go to the fi rst or last two bits of an S-box in the next round. The
other two output bits go to the middle bits of an S-box in the next round.
7. If an output bit from Sj goes to one of the middle bits in Sk (in the next round), then an output bit from
Sk cannot go to the middle bit of Sj . If we let j = k, this implies that none of the middle bits of an S-box can
go to one of the middle bits of the same S-box in the next round.
Unit-2: Classical and Symmentric Key Cryptography 111
Block cipher design principles
The design of the block cipher is based on the three principles, which
are
1. Number of Rounds
2. Design of function F
3. Key schedule algorithm
1. Number of Rounds:
• In this, the number of rounds will judge the block cipher algorithm’s strength.
• It is thought that if the number of rounds is more, it makes it difficult for the
cryptanalysis to break into the algorithm.
• Even in case, the function F stays weak, then the number of rounds makes it
challenging to get into the algorithm and break it.
C1 C2 CN
64-bit 64-bit 64-bit
K K K
Decrypt Decrypt … Decrypt
𝐶 𝑗 =𝐸 ( 𝐾 , 𝑃 𝑗 ) 𝑗=1 , .., 𝑁
𝑃 𝑗 =𝐷 ( 𝐾 , 𝐶 𝑗 ) 𝑗=1 ,.. , 𝑁
C1 C2 CN
C1 C2 CN
K K K
Decrypt Decrypt … Decrypt
IV CN-1
P1 P2 PN
Cipher Block Chaining (CBC) (cont…)
𝐶 1= 𝐸 ¿
𝑃 1= 𝐷 ( 𝐾 ,𝐶 1 )⊕ 𝐼𝑉
Select Discard
s bits b-s bits
Select Discard
s bits b-s bits
… Select Discard
s bits b-s bits
S bits S bits S bits
s bits
P1 P2 PN
s bits
C1 C2 CN
S bits S bits S bits
Select Discard
s bits b-s bits
Select Discard
s bits b-s bits
… Select Discard
s bits b-s bits
C1 C2 CN
S bits S bits S bits
P1 P2 PN
S bits S bits S bits
P1 P2 PN
C1 C2 CN
C1 C2 CN
P1 P2 PN
P1 P2 PN
C1 C2 CN
𝐶 𝑗 =𝑃 𝑗 ⊕ 𝐸 ( 𝐾 ,𝑇 𝑗 ) 𝑗=1 , .. , 𝑁
C1 C2 CN
P1 P2 PN
𝑃 𝑗 =𝐶 𝑗 ⊕ 𝐸 ( 𝐾 ,𝑇 𝑗 ) 𝑗=1 , .. , 𝑁
End of Unit-2