0% found this document useful (0 votes)
183 views41 pages

Section 03 - Classical Encryption Techniques II

The document summarizes classical encryption techniques, including the Hill cipher, polyalphabetic ciphers using a repeating key or autokey, and transposition techniques like the rail fence cipher. It provides details on how the Hill cipher uses a key matrix to encrypt plaintext letters into ciphertext letters through a linear equation. It also explains how the inverse key matrix is calculated to decrypt ciphertext in the Hill cipher. Polyalphabetic ciphers are described as using the Vigenere tableau and a keyword to generate a keystream to substitute plaintext letters.

Uploaded by

Bassem Mohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views41 pages

Section 03 - Classical Encryption Techniques II

The document summarizes classical encryption techniques, including the Hill cipher, polyalphabetic ciphers using a repeating key or autokey, and transposition techniques like the rail fence cipher. It provides details on how the Hill cipher uses a key matrix to encrypt plaintext letters into ciphertext letters through a linear equation. It also explains how the inverse key matrix is calculated to decrypt ciphertext in the Hill cipher. Polyalphabetic ciphers are described as using the Vigenere tableau and a keyword to generate a keystream to substitute plaintext letters.

Uploaded by

Bassem Mohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

Cryptography and Network Security

Section 3

Chapter 3: Classical Encryption Techniques

1
Syllabus
Lab Lab Topics
1 Introduction
2 Classical Encryption techniques I
3 Classical Encryption techniques II
4 DES
5 block cipher operations & 3DES
6 AES
7 Quiz 1
8 Public-Key Cryptography & RSA
9 Hash functions & SHA-512
10 User Authentication (Kerberos)
11 IEEE 802.11 Wireless LAN protocol
2
Outlines:
 Classical Encryption Techniques
 Substitution Techniques
 Hill Cipher
 Polyalphabetic
 Repeating key
 AutoKey
 One-Time
 Transposition Technique
 Rail fence
 Columnar
 Multistage Transposition

3
Hill Cipher
 Mathematical Approach
 Multiple letters substitution takes m successive P.T
letters and substitutes them by m C.T letters
 Encryption is done by linear equation:

m C.T Letters = mxm Key Matrix multiplied by m P.T Letters

4
A 0
B 1

Hill Cipher - Encryption


C 2
D 3
E 4

Example: F
G
5
6

 P.T = pay more money H 7


I 8
 m=3 J 9
K 10
L 11
M 12
N 13
O 14
P 15
Q 16
R 17
S 18
T 19
U 20
V 21
W 22
X 23
Y 24
Z 25

5
A 0
B 1

Hill Cipher
C 2
D 3
Decryption? E 4
Solution F 5
G 6
H 7
I 8
J 9
K 10
L 11
M 12
N 13
O 14
P 15
Q 16
R 17
S 18
T 19
U 20
V 21
W 22

🞂 And so on… then the C.T = LNS HDL…….. X 23


Y 24
Z 25

6
Hill Cipher - Decryption
🞂 Decryption is done by the inverse of encryption linear
equation:

🞂 How to find inverse ?


For a 2×2 matrix For a 3×3 matrix !!!

7
Hill Cipher – Decryption(Cont.)

Calculating the determinant 

8
Hill Cipher - Decryption(Cont.)

Conditions of key Matrix that guarantee the existence of k-1


I. All elements are nonnegative and less than 26

II. No common factors between det(k) and 26


(GCD (26,det(k)) =1)

III. det(k) not equal zero


9
Hill Cipher - Decryption(Cont.)

10
11
Hill Cipher - Decryption(Cont.)

12
Hill Cipher - Decryption(Cont.)

13
Hill Cipher - Decryption
HOW to find the inverse key matrix (other method)
General rule:

K-1ij ={b x (-1)i+j * Dij mod 26} mod 26

b: multiplicative inverse of matrix determinant


b=1/det(k)=det(k)-1 , but fraction has NO meaning in our
system which understands numbers between 0 to 25 only …
in other terms ( b x det(k) mod 26 = 1)

Dij : sub-determinant of row I and column J

14
Hill Cipher - Decryption
HOW to find the inverse key matrix K-1

1. Calculate det(k) mod 26

2. Calculate the Multiplicative Inverse b of matrix determinant


b=1/det(k)=det(k)-1

3. Apply rule kij ={b x (-1)i+j * Dij mod 26} mod 26

K-1ij ={b x (-1)i+j * Dij mod 26} mod 26

Dij : sub-determinant of row I and column J

4. K-1 = transpose of output of step 3

15
A 0
B 1

Hill Cipher - Decryption


C 2
D 3
E 4

Example: F
G
5
6

🞂 P.T = LNS HDL EWM TRW H 7


I 8
🞂m = 3 J 9
K 10
🞂 L 11
M 12
N 13
O 14
P 15
Q 16
R 17
S 18
T 19
U 20
V 21
W 22
X 23
Y 24
Z 25

16
Hill Cipher - Decryption
First we have to find the inverse key matrix
1- Calculate det(k) mod 26
det(k) = 17(18*19-2*21)
-17(21*19-2x21)
+ 5(21*2-18*2) = -939 mod 26 = 23

2- Calculate b = det(k) -1 ( b x det(k) mod 26 =1 )


b x det (k) mod 26 = 1
b x 23 mod 26 = 1
(26 – c) (26 – 3) mod 26 = 1
262 – 26c - 3x26 + 3c mod 26 = 1
3c mod 26 = 1
3c = 1 🡺 c = 1/3 …. Doesn’t fit
3c = 27 🡺 c = 9 …. This is the answer then b = 26 – c = 26 -9 = 17
3c = 53 …
17
Hill Cipher - Decryption
First we have to find the inverse key matrix
3- Apply rule kij ={b x (-1)i+j * Dij mod 26} mod 26
K00= 17 *(-1)0+0( 18*19-21*2) mod 26 =4
K01= 17 *(-1)0+1( 21*19-21*2) mod 26 = 15
K02= 17 *(-1)0+2( 21*2-18*2) mod 26 = 24
K10= 17 *(-1)1+0( 17*19 –2*5) mod 26 = 9
K11= 17 *(-1)1+1( 17*19-2*5) mod 26 = 17
K12= 17 *(-1)1+2( 17*2-17*2) mod 26 = 0
K20= 17 *(-1)2+0( 17*21-18*5) mod 26 = 15
K21= 17 *(-1)2+1( 17*21-21*5) mod 26 = 6
K22= 17 *(-1)2+2( 17*18-17*21) mod 26 = 17

4- Final K-1 = transpose K-1

18
A 0
B 1

Hill Cipher - Decryption


C 2
D 3
E 4

Example: F 5
G 6
🞂 C.T = LNS HDL EWM TRW Cryptanalysis
H 7
?
🞂m = 3 I
J
8
9

🞂 K
L
10
11
M 12
N 13
Solution: O 14
P 15
Q 16
R 17
S 18
T 19
U 20
V 21
W 22
🞂 And so on …. P.T = pay….. X 23
Y 24
Z 25

19
Hill Cipher - Ctyptanalysis
🞂 High security against C.T only attack
🞂 Zero security against known P.T Attack (why !)

20
Outlines:
🞂Classical Encryption Techniques
🞂Substitution Techniques
🞂Hill Cipher
🞂Polyalphabetic
◻Repeating key
◻AutoKey
◻One-Time

🞂Transposition Technique
🞂Rail fence
🞂Columnar
🞂Multistage Transposition

21
Polyalphabetic
All of Polyalphabetic cipher versions based on using vigenere tableau

Steps:
🞂 Given a key word generate the key stream
🞂 Substitute each P. T letter with a C.T letter based on the corresponding key
letter using vigenere tableau

22
Polyalphabetic
All of Polyalphabetic cipher versions based on using vigenere tableau

Repeating key Autokey One time pad


Repeat the Append the P.T The keyword is of
keyword till we with the keyword length of length
get a key stream to get a key as same as the P.T
of length as same stream of length length so the
as the P.T length as same as the P.T keyword is the
length key stream

23
Polyalphabetic: Vigenere with Repeating key
Example:
🞂 Keyword = hello
🞂 P.T = Computer
🞂 Key-stream =hellohel

P.T c o m p u t e r
k-stream h e l l o h e l
C.T J S X A I A I C

24
Polyalphabetic: Vigenere with Repeating key
Example:
🞂 Keyword = hello
🞂 P.T = Computer
🞂 Key-stream =hellohel

P.T c o m p u t e r
k-stream h e l l o h e l
C.T J S X A I A I C

Decryption?

25
Polyalphabetic: Vigenere with Auto-Key
Example:
🞂 Keyword = hello
🞂 P.T = Computer
🞂 Key-stream =hellocom

P.T c o m p u t e r
k-stream h e l l o h e l
C.T J S X A I A I C

26
Polyalphabetic: Vigenere with Auto-Key
Example:
🞂 Keyword = hello
🞂 P.T = Computer
🞂 Key-stream =hellocom

P.T c o m p u t e r
k-stream h e l l o c o m
C.T J S X A I V S D

Decryption?

27
Polyalphabetic: one-time-pad (Theoretical Scheme)
Example:
🞂 Keyword = key-stream = hilmotry
🞂 P.T = Computer

P.T c o m p u t e r
k-stream h e l l o h e l
C.T J S X A I A I C

28
Polyalphabetic: one-time-pad (Theoretical Scheme)
Example:
🞂 Keyword = key-stream = hilmotry
🞂 P.T = Computer

P.T c o m p u t e r
k-stream h i l m o t r y
C.T J W X B I M V P

🞂 Problems:
Decryption?
1. Key generation
2. Key distribution

29
Outlines:
🞂Classical Encryption Techniques
🞂Substitution Techniques
🞂Hill Cipher
🞂Polyalphabetic
◻Repeating key
◻AutoKey
◻One-Time
🞂Transposition Technique
🞂Rail fence
🞂Columnar
🞂Multistage Transposition

30
cryptanalys
Rail Fence is !
How
🞂 Write P.T column wise ( consider the depth ) and read it row wise
Example Example:
🞂 P.T : Computer Science 🞂 P.T : Computer Science
🞂 Key = depth = 2 🞂 Key = depth = 3
  c m u e s i n e   c p e c n
o p t r c e c o u r i c
m t s e e

🞂 C.T = CMUESINEOPTRCEC 🞂 C.T = CPECNOURICMTSEE


Decryption : Decryption :
🞂 P.T length =15/ depth = 7.5 =8 🞂 P.T length =15/ depth = 5

31
Multistage !
Columnar
How
🞂 P.T row wise (consider number of columns) and read it column wise
( consider the permutation)
🞂 Key = number of columns with certain permutation = 1 3 4 2 5

Example Example
🞂 P.T : Computer Science P.T : Computer Science
🞂 Key = 1 3 4 2 5 Key = 1 4 3 2
   c
c o m p u o m p
t e r s c u t e r
i e n c e s c i e
n c e x

C.T = CTIPSCOEEMRNUCE C.T = CUSNPREXMEIEOTCC


Decryption ?? Decryption ??

32
A 0
B 1

Problems to be discussed
C 2
D 3
E 4
This problem explores the use of a one-time pad version of the Vigenère cipher. F 5

In this scheme, the key is a stream of random numbers between 0 and 26. G 6
H 7
For example, if the key is 3 19 5 ..., then the first letter of plaintext is encrypted with a I 8
shift of 3 letters, the second with a shift of 19 letters, the third with a shift of 5 letters, J 9
and so on. K 10

a. Encrypt the plaintext “sendmoremoney” with the key stream L 11


M 12
9 0 1 7 23 15 21 14 11 11 2 8 9. N 13
b. Using the ciphertext produced in part a, find a key so that the cipher text decrypts O 14
to the plaintext cashnotneeded. P 15
Q 16
R 17
P.T s e n d m o r e m o n e y S 18
T 19
key 9 0 1 7 2 1 2 1 11 11 2 8 9 U 20
3 5 1 4 V 21

C.T W 22

? X 23
Y 24
Key Z 25

33
?
P. T c a s h n o t n e e d e d
Solution

PT s e n d m o r e m o n e y

PT 18 4 13 3 12 14 17 4 12 14 13 4 24

Key 9 0 1 7 23 15 21 14 11 11 2 8 9

CT 1 4 14 10 9 3 12 18 23 25 15 12 7

CT B E O K J D M S X Z P M H

Key 25 4 22 3 22 15 19 5 19 21 12 8 4

P. T c a s h n o t n e e d e d

34
A 0
B 1

Your turn ☺
C 2
D 3
E 4
Encrypt the following message F 5
G 6
“Advance the attack three hours” using H 7

🞂 A.) Double stage rail fence with depth 3. I 8


J 9
🞂 B.) Double stage Columnar with key 5 1 4 2 3. K 10
L 11
M 12
N 13
O 14
P 15
Q 16
R 17
S 18
T 19
U 20
V 21
W 22
X 23
Y 24
Z 25

35
Solution
Encrypt the following message
“Advance the attack three hours” using
A.) Double stage rail fence with depth 3.

a a e e t k r h r
d n t a a t e o s
v c h t c h e u x
aaeetkrhrdntaateosvchtcheux

a e r d a e v t e
a t h n a o c c u
e k r t t s h h x
aerdaevteathnaoccuekrttshhx

36
Solution
Encrypt the following message
“Advance the attack three hours” using
B.) Double stage Columnar with key 5 1 4 2 3.

5 1 4 2 3 5 1 4 2 3
a d v a n d e t t h
c e t h e x a h a r
a t t a c u x n e c
k t h r e e r x v t
e h o u r t h o x a
s x x x x c a k e s
detthxaharuxnecerxvtthoxacakes eaxrhataevxehrctasthnxokdxuetc

37
Additional Problems:
1 - Suppose plaintext “FRIDAY” encrypted using 2x2 hill cipher to yield text
“PQCFKU” Deduce and verify the key.
 
2- Cipher text “SDEK” is obtained by encrypting a message (M) using a playfair with
“Cryptography” as a keyword or by using Hill cipher (2x2) key. Find and verify
key. (Final 2009 – Midterm 2010)
 
3- Encrypt the following message
“Advance the attack three hours” using
a) Ceaser cipher with k=3.
b) Playfair key “beginning”
c) Vigenere with Auto key “Confusion”.
d) Vigenere with Repeating key “Confusion”.
e) Double stage rail fence with depth 3.
f) Double stage Columnar with key 5 1 4 2 3.
 
4- Decrypt cipher text generated in Question (3) using the same key and technique in
each point.
38
 
Package Milestone 2
Deadline: 30th October 2022
You should implement the following:
 HillCipher
 public List<int> Encrypt(List<int> plainText, List<int> key)
 public List<int> Decrypt(List<int> cipherText, List<int> key)
 public List<int> Analyse(List<int> plainText, List<int> cipherText) // 2*2
key
 public List<int> Analyse3By3Key(List<int> plain3, List<int> cipher3)
 In analysis, In case of invalid key  throwInvalidAnlysisException
 RepeatingkeyVigenere:
 public string Encrypt(string plainText, int key)
 public string Decrypt(string cipherText, int key)
 public int Analyse(string plainText, string cipherText)

39
Package Milestone 2(Cont.)
Deadline: 30th October 2022
You should implement the following:
 AutokeyVigenere
 public string Encrypt(string plainText, int key)
 public string Decrypt(string cipherText, int key)
 public int Analyse(string plainText, string cipherText)
 RailFence
 public string Encrypt(string plainText, int key)
 public string Decrypt(string cipherText, int key)
 public int Analyse(string plainText, string cipherText)
 Columnar
 public string Encrypt(string plainText, List<int> key)
 public string Decrypt(string cipherText, List<int> key)
 public List<int> Analyse(string plainText, string cipherText)
40
41

You might also like