Professional Documents
Culture Documents
Lecture 4
Classical
Cryptography
Previous lecture
RECAP
Extended Euclidean
Algorithm
Given a,b, solve for a.x + b.y=d, to determine the values of x & y. Let a=12345, b=11111, be the two integers,
we have already calculated gcd(12345,11111)=1, so we can write:
gcd(12345, 11111)=1=n*12345 + s*11111,
The problem is to determine the values of n & s ???
How to find?
1. Use the Extended Euclidean Algorithm to find integers s and t, such that a*s +
n*t=1
2. a-1≡ s mod n
From last slide
1=(– 2224)*12345 + (2471)*11111
Verification:
S=-2224, t= 2471
a * a-1≡1 mod 11111
a-1 ≡ s mod n 12345 *8887≡1 mod 11111
-2224≡ (-1)(11111) + 8887
a-1=8887
Cryptanalysis of the
Affine Cipher (1)
Consider the Cipher-text:
Hypothesis 1
R is encryption of e eK(4) = 17
D is encryption of t eK(19) = 3
Recall that , ek(x)=a*x + b, thus
4a + b=17 a=6 in Z26
19a + b=3 B=19
Hypothesis 2
R is encryption of e eK(4) = 17
E is encryption of t eK(19) = 4
Recall that , ek(x)=a*x + b, thus
4a + b=17 a=13 in Z26
19a + b=4 b=17
Hypothesis 3
R is encryption of e eK(4) = 17
H is encryption of t eK(19) = 7
Recall that , ek(x)=a*x + b, thus
4a + b=17 a=8 in Z26
19a + b=7 b=11
19 7 8 18 2 17 24 15 19 14 18 24
K 2 8 15 7 4 17 2 8 15 7 4 17
21 15 23 25 6 8 0 23 8 21 22 15
C V P X Z G I A X I V W P
P s t e m i s n o t s e c u R e
18 19 4 12 8 18 13 14 19 18 4 2 20 17 4
K 2 8 15 7 4 17 2 8 15 7 4 17 2 8 15
20 1 19 19 12 9 15 22 8 25 8 19 22 25 19
C U B T T M J P W I Z I T W Z T
• So,
First step: determine the key length=m,
Second step: determine the key (word) itself
After that decryption of the message is easy.
The Permutation Cipher
x 1 2 3 4 5 6 c 1 2 3 4 5 6
-1
π(x) 5 1 6 3 2 4 π (c) 2 5 4 6 1 3
x 1 2 3 4 5 6
π(x) 3 5 1 6 4 2
x 1 2 3 4 5 6
Π-1(x) 3 6 1 5 2 4
Rail Fence cipher
• write message letters out diagonally over a number
of rows
• then read off cipher row by row
• eg. write message out as:
m e m a t r h t g p r y
e t e f e t e o a a t
• giving ciphertext
MEMATRHTGPRYETEFETEOAAT
Row Transposition Ciphers
• a more complex transposition
• write letters of message out in rows over a
specified number of columns
• then reorder the columns according to some
key before reading off the rows
Key: 4 3 1 2 5 6 7
Plaintext: a t t a c k p
o s t p o n e
d u n t i l t
w o a m x y z
Ciphertext: TTNAAPTMTSUOAODWCOIXKNLYPETZ
Product Ciphers
• ciphers using substitutions or transpositions are not
secure because of language characteristics
• hence consider using several ciphers in succession to
make harder, but:
– two substitutions make a more complex substitution
– two transpositions make more complex transposition
– but a substitution followed by a transposition makes a new
much harder cipher
• this is bridge from classical to modern ciphers
The Hill Cipher
A B C D E F G H I J K L M N 0 P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
The Hill Cipher
Example:
• Encrypting a message using the Hill Cipher is very simple. Decryption however is
more challenging.
• Suppose the key (K) is
11 8
k
3 7
• We can compute K-1, which is,
7 18
k
23 11
• We are given the following ciphertext “july”, we need to encrypt two pieces of
plaintext ju (9,20) and ly (11,24):
11 8
9 20 99 60, 72 40 3, 4
3 7
and
11 24
11 8
121 72, 88 168 11 22
3 7
7 18
3 4 21 92, 54 44 9, 20
and 23 11
7 18
11 22 77 506, 198 242 11, 24
23 11
• Hence the correct plaintext is obtained
MRGFNIATXZQVFFNUXFFYBTCE25TYXIIXGZKACJLRGKQYEIX
OYYAUAPXYIJLHPRGVTSFPAYNNYURZOPHXWYXLFRNUTZBR
FKAHFWFZESYUWZMOLLBSBZBJHFPLXKHVIVMZTZHUIWAET
IUEDFGLXDIEXIYJIUXPNNEIXABVCINTVCIEZYYDAZGZIW
181TYXJIKTRZLMFFKALGZNVKZXIIMXUUNAPGVXFUSMISKHVY
VOCRVXRIW235TYXZOIRFNUXZNXLDUDPZGVHVOWMOYJERLAUG
LVTUXTHRBUQZTYTXORNKBASFFXGHQVDSHUYJSYHDYUWYX
YYKHVTUCDACAHXSEVGJIEFZGLXRSBXSYKOEPPNYAKTUAC
EFYILFWEAHCIAUALLZNXMVCKLRRHGFNXMOYUESKPM
Index of Coincidence
• Now we will use the index of coincidence to see if it gives the same result.
• The index of coincidence is defined as follows:
n n(n 1)
2
Index of Coincidence
• Index of coincidence of a string written in English is approximately
equal to 0.065. Table 1
25
Ic ( x ) pi2 0.065
i 0
(d) Share 1
(e) Share 2
4 3/14/2023
5 (f) Stacking 1 & 2