Chapter5 Slides
Chapter5 Slides
Chapter 5 – Enciphering 1 / 86
Overview
1 Early cryptosystems
Transposition & substitutiton systems
Shift transformation
2 Frequency analysis
3 Vignere Cipher
4 Affine Cryptosystems
Chapter 5 – Enciphering 2 / 86
Introduction
Chapter 5 – Enciphering 3 / 86
Introduction
Cryptography
Chapter 5 – Enciphering 4 / 86
Introduction
Chapter 5 – Enciphering 5 / 86
Introduction
DGYDQFH.
Chapter 5 – Enciphering 6 / 86
Introduction
Chapter 5 – Enciphering 7 / 86
Rail Fence
Chapter 5 – Enciphering 8 / 86
Suppose the original message is
MEETATYISHUNSTATION.
M E A Y S U S A I N
E T T I H N T T O
MEAYSUSAINETTIHNTTO.
Chapter 5 – Enciphering 9 / 86
We can juxtapose in a different way to form the concealed message:
ETTIHNTTOMEAYSUSAIN.
Chapter 5 – Enciphering 10 / 86
Rail Fence
Generalized Rail Fence Transposition
Juxtapose these three lines of letters into one single line of letters. This
can be done is several ways:
L1 L2 L3
or
L2 L1 L3
or
L3 L2 L1
and so on.
This line of letters will be conveyed or transmitted.
Chapter 5 – Enciphering 12 / 86
Shift transformation
Caesar’s code, which shifts each letter of the alphabet forward by three
places, is the earliest documented use of a substitution cipher for military
purposes.
The letters are arranged in a circle in a clockwise direction and the shifting
is done three places in the clockwise direction.
X → A, Y → B, Z → C , A → D.
Chapter 5 – Enciphering 13 / 86
Shift transformation
N O P Q R S T U V W X Y Z
13 14 15 16 17 18 19 20 21 22 23 24 25
Chapter 5 – Enciphering 14 / 86
Shift transformation
y ≡ x +k (mod 26).
Chapter 5 – Enciphering 15 / 86
Shift transformation
Example 5.4
Apply the shift transformation with k = 15 to the message
MEET AT NOON.
12 4 4 19 0 19 13 14 14 13.
Chapter 5 – Enciphering 16 / 86
Shift transformation
x 12 4 19 0 13 14
x + 15 27 19 34 15 28 29
y 1 19 8 15 2 3
1 19 19 8 15 8 2 3 3 2
or in letters
BTTI PI CDDC .
Chapter 5 – Enciphering 17 / 86
Shift transformation
Example 5.5
Suppose a PIN (personal identification number) number is a sequence of 6
digits x1 x2 x3 x4 x5 x6 such that 0 ≤ xi ≤ 9 for 0 ≤ i ≤ 6.
Chapter 5 – Enciphering 18 / 86
Shift transformation
y 8 0 3 2 5 6
y −4 4 −4 −1 −2 1 2
x 4 6 9 8 1 2
Chapter 5 – Enciphering 19 / 86
Frequency analysis
Frequency analysis:
E T A O I N S H R
12.7% 9.1% 8.2% 7.5% 7.0% 6.7% 6.3% 6.1% 6.0%
Chapter 5 – Enciphering 20 / 86
Frequency analysis
Example 5.6
Suppose the following encrypted message is received:
Chapter 5 – Enciphering 21 / 86
Frequency analysis
25 ≡ 4 + k (mod 26).
x ≡ y − 21 ≡ y + 5 (mod 26),
EZ GNN · · ·
which is gibberish.
Chapter 5 – Enciphering 22 / 86
Frequency analysis
25 ≡ 19 + k (mod 26).
Chapter 5 – Enciphering 23 / 86
Vignere Cipher
Chapter 5 – Enciphering 24 / 86
Vignere Cipher
Vignere Cipher:
Write the keyword repeatedly in a row above the row of the message
– one letter of the keyword above one letter of the message.
Chapter 5 – Enciphering 25 / 86
Vignere Cipher
Vignere square:
Chapter 5 – Enciphering 26 / 86
Vignere Cipher
Example 5.7
With the keyword “ostrich”, use the Vignere Cipher to encrypt the message
Chapter 5 – Enciphering 27 / 86
Vignere Cipher
OTBILKUHZXYIPKWKPFZVOHOHZVVOSTNJP.
Chapter 5 – Enciphering 28 / 86
Vignere Cipher
Example 5.8
Suppose the keyword for a Vignere Cipher is dog . The encrypted message
is
LOSKITJFE .
Find the original message.
Answer:
I AM . . .
Chapter 5 – Enciphering 29 / 86
Multiplicative inverse modulo n
Remark
If ab ≡ 1 (mod n), then a is an inverse of b and b is an inverse of a. i.e.,
they form an inversive pair.
Example 5.10
The number 8 is an inverse of 2 modulo 5 since
Chapter 5 – Enciphering 31 / 86
Multiplicative inverse modulo n
Remark
When one tries to find an inverse of a modulo n, one needs to check for
values between 1 and n − 1 since the value of the remainder lies in this
range.
Chapter 5 – Enciphering 32 / 86
Multiplicative inverse modulo n
Example 5.11
The number 2 does not have an inverse modulo 6 since
2 × 1, 2 × 2, . . . , 2 × 5
Chapter 5 – Enciphering 33 / 86
Multiplicative inverse modulo n
Example 5.12
Find the inverse of 2 modulo 7.
Remark
When n is small, we can use this method. We’ll learn another method for
large n.
Chapter 5 – Enciphering 34 / 86
Multiplicative inverse modulo n
Example 5.13
Find all inverse pairs modulo 10.
Chapter 5 – Enciphering 35 / 86
Multiplicative inverse modulo n
Example 5.14
Find all inverse pairs modulo 26.
(1, 1), (3, 9), (5, 21), (7, 15), (11, 19), (17, 23), (25, 25)
The other numbers between 1 and 25 do not have an inverse modulo 26.
Chapter 5 – Enciphering 36 / 86
Affine Cryptosystems
y = f (x) ≡ ax + b (mod n)
where
n is the total number of letters and symbols that may be used in the
plaintext. Usually, n = 26.
the pais (a, b) is called the key of the affine crypto system.
Chapter 5 – Enciphering 37 / 86
Affine Cryptosystems
Remark
The key (1, 0) is admissible but it is useless. Why?
Chapter 5 – Enciphering 38 / 86
Affine Cryptosystems
Chapter 5 – Enciphering 39 / 86
Affine Cryptosystems
Chapter 5 – Enciphering 40 / 86
Affine Cryptosystems
x = f −1 (y ) ≡ a0 y − a0 b (mod 26)
Chapter 5 – Enciphering 41 / 86
Affine Cryptosystems
Remark
Since a does not have an inverse modulo 26 when a is even or when
a = 13, the condition on a is necessary to enable the deciphering.
Chapter 5 – Enciphering 42 / 86
Affine Cryptosystems
Example 5.17
Using the affine cryptosystem on 26-letter alphabet with key (3, 5), the
encrypted message is
HRMM SVT .
Decipher the encrypted message.
x = f −1 (y ) ≡ 9y − 45 ≡ 9y + 7 (mod 26).
Chapter 5 – Enciphering 43 / 86
Affine Cryptosystems
letter H R M M S V T
y 7 17 12 12 18 21 19
9y + 7 70 160 115 115 169 196 178
x 18 4 11 11 13 14 22
letter S E L L N O W
Chapter 5 – Enciphering 44 / 86
Greatest common divisor (GCD)
Definition 5.18
Let a and b be integers, not both zero.
Chapter 5 – Enciphering 45 / 86
Greatest common divisor (GCD)
Example 5.19
The common divisors of 72 and 63 are 1, 2 and 9. Thus gcd(72, 63) = 9.
Chapter 5 – Enciphering 46 / 86
Greatest common divisor (GCD)
Example 5.20
Let n be a positive integer. The common divisors of 0 and n are all the
divisors of n. Thus gcd(0, n) = n.
Example 5.21
Let n be a positive integer. There is only one common divisor of 1 and n,
namely, the number 1. Thus gcd(1, n) = 1.
Chapter 5 – Enciphering 47 / 86
Euclidean algorithm
Theorem 5.22
Let a, b, q, r be integers such that a = bq + r . Then
gcd(a, b) = gcd(b, r ).
Chapter 5 – Enciphering 48 / 86
Euclidean algorithm
Proof.
Let d = gcd(a, b), e = gcd(b, r ). (Our aim is to prove that d = e.)
∴ d is a divisor of r .
∴ d ≤ e.
Given two integers n and a, where 0 < a < n, we divide n by a and make a
series of such divisions which eventually terminate with a zero remainder.
The ri ’s are the remainders.
n = a q1 + r1 , (divide n by a)
a = r1 q2 + r2 , (divide a by r1 )
r1 = r2 q3 + r3 , (divide r1 by r2 )
..
.
rj−3 = rj−2 qj−1 + rj−1 , (divide rj−3 by rj−2 )
rj−2 = rj−1 qj + rj , (divide rj−2 by rj−1 )
rj−1 = rj qj+1 + 0. (STOP)
Chapter 5 – Enciphering 50 / 86
Euclidean algorithm & GCD
Note that
gcd(n, a) = gcd(a, r1 )
gcd(a, r1 ) = gcd(r1 , r2 )
gcd(r1 , r2 ) = gcd(r2 , r3 )
..
.
gcd(rj−2 , rj−1 ) = gcd(rj−1 , rj )
gcd(rj−1 , rj ) = gcd(rj , 0) = rj
Therefore gcd(n, a) = rj .
Chapter 5 – Enciphering 51 / 86
Euclidean algorithm & GCD
Remark
Using the Euclidean algorithm, we can write the gcd, rj , in terms of n and
a. We simply work backwards.
Chapter 5 – Enciphering 52 / 86
Euclidean algorithm & GCD
Start from the last equation with nonzero remainder. Write rj as the
subject of the formula:
rj = rj−2 − rj−1 qj
Use the preceding equation, replace rj−1 with its expression in terms of
rj−2 and rj−3 .
rj = rj−2 − (rj−3 − rj−2 qj−1 )qj
= rj−2 (1 + qj−1 qj ) − rj−3 qj
Continue this process successively, replacing rj−2 , rj−3 , . . ., until you
obtain the final equation
rj = ax + ny ,
with x and y integers.
Chapter 5 – Enciphering 53 / 86
Euclidean algorithm & GCD
Example 5.23
Find gcd(7, 480) using the Euclidean algorithm. Then write the GCD in
terms of 7 and 480.
480 = 7 · 68 + 4
7 = 4 ·1+ 3
4 = 3 ·1+ 1
3 = 1 · 3 + 0.
1 = 4 − 3 ·1
= 4 − ( 7 − 4 · 1) · 1 = 4 · 2 − 7
= ( 480 − 7 · 68) · 2 − 7 = 480 · 2 − 7 · 137
Therefore
1 = 480 · 2 − 7 · 137
Chapter 5 – Enciphering 55 / 86
Multiplicative inverse & GCD
Theorem 5.24
Suppose a has an inverse b modulo n. Then gcd(a, n) = 1.
Proof
We have
ab ≡ 1 (mod n).
Thus there is an integer k such that
ab = kn + 1
Chapter 5 – Enciphering 56 / 86
Multiplicative inverse & GCD
Theorem 5.25
Suppose a, n are positive integers. If gcd(a, n) = 1, then a has an inverse
modulo n.
Proof
We can write the gcd, which is 1, in terms of a and n:
1 = ax + ny .
Chapter 5 – Enciphering 57 / 86
Multiplicative inverse & GCD
Chapter 5 – Enciphering 58 / 86
Euclidean algorithm & Multiplicative inverse
Example 5.27
Find an inverse of 7 modulo 480
Solution:
We already have
1 = 480 · 2 − 7 · 137
Take mod 480, we have
Therefore −137 in an inverse. Add 480 to it, we get the answer 343.
(We usually want an answer between 1 and n − 1 and in this case
n = 480.)
Chapter 5 – Enciphering 59 / 86
Modular exponentiation
Chapter 5 – Enciphering 60 / 86
Modular exponentiation
Example 5.28
Find the remainder when 223 is divided by 9.
Solution:
We can proceed by using mod. (Here all the congruences are (mod 9).
22 ≡ 4, 23 ≡ 8
25 ≡ 4 × 8 ≡ 5, 210 ≡ (25 )2 ≡ 25 ≡ 7
220 ≡ (210 )2 ≡ 49 ≡ 4 223 ≡ 220 23 ≡ 4 × 8 ≡ 5
Chapter 5 – Enciphering 61 / 86
Modular exponentiation
Modular exponentiation
Find the remainder of an when divided by m, where a and n are large
numbers.
Step 1. Express n in binary form.
Step 2. Write n as a sum of powers of 2.
Step 3. Write an = ab1 ab2 . . . abk where each bi is a power of 2.
Step 4. Compute the remainder ri when abi is divided by m.
Step 5. Find the remainder when the product r1 r2 . . . rk is divided by m to
get the answer.
Chapter 5 – Enciphering 62 / 86
Modular exponentiation
Example 5.29
Find the remainder when 223 is divided by 9.
Step 1: 22 = (10111)2
Step 2: 10 = 24 + 22 + 21 + 1 = 16 + 4 + 2 + 1.
Step 3: 210 = 216+4+2+1 = 216 24 22 21 .
Chapter 5 – Enciphering 63 / 86
Modular exponentiation
Remark
Steps 1, 2 can be done as follows:
First write down all powers of 2 which are ≤ 10: 1, 2, 4, 8, 16.
Then 23 − 16 = 7, 7 − 4 = 3, 3 − 2 = 1. Thereofore
23 = 16 + 4 + 2 + 1
Chapter 5 – Enciphering 64 / 86
Modular exponentiation
2 ≡ 2
22 ≡ 4
24 ≡ (22 )2 ≡ 42 ≡ 7
28 ≡ (24 )2 ≡ 72 ≡ 4
216 ≡ (28 )2 ≡ 42 ≡ 7
Chapter 5 – Enciphering 65 / 86
Modular exponentiation
Example 5.30
Find the remainder when3101 is divided by 100.
Chapter 5 – Enciphering 66 / 86
Modular exponentiation
3 ≡ 3
32 ≡ 9
34 ≡ 92 ≡ 81
38 ≡ 812 ≡ 61
316 ≡ 612 ≡ 21
332 ≡ 212 ≡ 41
364 ≡ 412 ≡ 81.
Chapter 5 – Enciphering 67 / 86
Modular exponentiation
Remark
In general, if n = (ak . . . a1 a0 )2 , then 2k ≤ n < 2k+1 .
From here we deduce that k = blog2 nc.
The binary conversion also takes k steps.The squaring operation have to
be performed k times. Another k multiplications are needed to obtain the
final result.
Thus the total number of operations is roughly 3k.
This is much lower than the n operations that you’d need if you were to
perform the calculation by brute force.
For example if n = 1000, k = 9.
Chapter 5 – Enciphering 68 / 86
Fermat’s Little Theorem (FLT)
Theorem 5.31
Let p be a prime number and a be an integer which is not a multiple of p.
Then
ap−1 ≡ 1 (mod p).
Chapter 5 – Enciphering 69 / 86
Fermat’s Little Theorem (FLT)
Example 5.32
24 ≡ 1 (mod 5)
36 ≡ 1 (mod 7)
Chapter 5 – Enciphering 70 / 86
Public Key Codes: RSA
Its security depends on the ability to keep the key safe in two places:
the sender and the recipient.
Chapter 5 – Enciphering 71 / 86
Public Key Codes: RSA
the enciphering key may be made public, only the receiver has the
deciphering key.
Chapter 5 – Enciphering 72 / 86
Public Key Codes: RSA
Adi Shamir
Born: July 6, 1952 (age 62), Tel Aviv, Israel
Co-inventor of the RSA. Currently at Weizmann Institute of Science
Chapter 5 – Enciphering 74 / 86
Public Key Codes: RSA
RSA Encipering:
Pick two large primes p and q (in practice each has about 200 digits).
Let n = pq.
r ≡ Mk (mod n).
Chapter 5 – Enciphering 76 / 86
Public Key Codes: RSA
RSA Deciphering:
kj = t(p − 1)(q − 1) + 1.
Chapter 5 – Enciphering 77 / 86
Public Key Codes: RSA
is justified as follows:
We have
r j ≡ M(M (p−1) )t(q−1) ≡ M (mod p).
and
r j ≡ M(M (q−1) )t(p−1) ≡ M (mod q).
Thus r j − M are both multiples of p and q. Since p, q are distinct primes,
r j − M is a multiple of pq = n. Therefore
rj ≡ M (mod n).
Chapter 5 – Enciphering 78 / 86
Public Key Codes: RSA
Security of RSA:
The enciphering key (n, k) is public; anyone can use it for encryption.
The prime factors p and q of n are kept secret. If they are known, then
the deciphering key j can be worked out.
Chapter 5 – Enciphering 79 / 86
Public Key Codes: RSA
Chapter 5 – Enciphering 80 / 86
Public Key Codes: RSA
Example 5.33
Suppose the plaintext is M = 141. Determine the RSA ciphertext using
the public key (n, k) = (1537, 47).
Solution.The ciphertext is
Chapter 5 – Enciphering 81 / 86
Public Key Codes: RSA
47 = 32 + 8 + 4 + 2 + 1.
Chapter 5 – Enciphering 82 / 86
Public Key Codes: RSA
Example 5.34
Suppose the RSA ciphertext is r = 1252 using the public key
(n, k) = (1537, 47). Determine the plaintext given that 1537 = 29 × 53.
Chapter 5 – Enciphering 83 / 86
Public Key Codes: RSA
1456 = 47 · 30 + 46
47 = 46 · 1 + 1 .
∴ 1 = 47 − 46
= 47 − 1456 − 47 · 30
= 47 · 31 − 1456 .
∴ 1 ≡ 47 · 31 (mod 1456)
Chapter 5 – Enciphering 84 / 86
Public Key Codes: RSA
Chapter 5 – Enciphering 85 / 86
Public Key Codes: RSA
When we are given a message such as SELL NOW, we first convert it into
a number, using A = 01, B = 02, . . . , Z = 26, space = 27 so that each
symbol is represented by 2 digits. In this case we get a 16 digit number.
They will need to be broken into blocks of equal size so that each block is
a number < n. For example if n has 5 digits, you’ll need to break it up
into 4 blocks, each of size 4. If n has 6 digits, you append 4 copies of 0 on
the left to make it a 20-digit number and break it up into 4 blocks each of
size 5.
Chapter 5 – Enciphering 86 / 86