Transcript Lecture 13

Elements of Coding and
Encryption
Continuation
1
Greatest Common Divisor
• Given integers m and n, not both zero, we
define the greatest common divisor of m and
n to be the largest integer that divides both m
and n: GCD(m, n).
• Note that if m ≠ 0, then GCD(m, 0) = |m|.
2
Greatest Common Divisor:
Euclidian Algorithm
• Determine the greatest common divisor (GCD) for
two numbers.
• Euclidean algorithm: GCD (a,b) can be recursively
found from the formula
if b =0
 a

GCD  a, b    b
if a =0
GCD  b, a mod b  otherwise

• Theorem. Let a, b, c, and q be integers with b>0. If
a=qb+c, then GCD(a, b) = GCD (b, c).
3
Euclidean Algorithm.
Example  
if b =0
 a

GCD a, b   b
if a =0
GCD  b, a mod b  otherwise

GCD(22,77):
Step
r = a mod b
a
b
0
-
22
77
4
Euclidean Algorithm.
Example  
if b =0
 a

GCD a, b   b
if a =0
GCD  b, a mod b  otherwise

GCD(22,77):
Step
r = a mod b
a
b
0
-
22
77
1
22 mod 77
= 22
77
22
5
Euclidean Algorithm.
Example  
if b =0
 a

GCD a, b   b
if a =0
GCD  b, a mod b  otherwise

GCD(22,77):
Step
r = a mod b
a
b
0
-
22
77
77
22
22
11
1
2
22 mod 77
= 22
77 mod 22
= 11
6
Euclidean Algorithm.
Example  
if b =0
 a

GCD a, b   b
if a =0
GCD  b, a mod b  otherwise

GCD(22,77):
Step
r = a mod b
a
b
0
-
22
77
77
22
22
11
11
0
1
2
3
22 mod 77
= 22
77 mod 22
= 11
22 mod 11
=0
7
Simple Encryption
•
1.
2.
3.
4.
Variations on the following have been used to
encrypt messages for thousands of years.
Convert a message to capitals.
Encode each letter by a number between 1 and 26.
Apply an invertible modular function to each
number.
Convert back to letters (0 becomes 26).
8
Letter  Number
Conversion Table
A
1
B
2
C
3
D
4
E
5
F
6
G
7
H
8
I J K L M
9 10 11 12 13
N O P Q R S T U V W X Y Z
14 15 16 17 18 19 20 21 22 23 24 25 26
9
Encryption example
•
•
1.
2.
3.
4.
Let the encryption function (“secret key”) be
f (a) = (3a + 9) mod 26
Encrypt “Stop Thief”
STOP THIEF
(capitals)
19,20,15,16 20,8,9,5,6
14,17,2,5 17,7,10,24,1
Scipher obtained: NQBE QGJXA
10
Decryption example
•
•


Decryption works the same, except that we apply
the inverse key function.
Find the inverse of
f (a) = (3a + 9) mod 26
If we didn’t have to deal with mod 26, inverse
would be
g (b) = 3-1 (b - 9)
We’ll see that since GCD(3,26) = 1, the inverse of 3
(mod 26) is the number 9. This gives:
g (b) = 9 (b - 9) mod 26 = (9b – 3) mod 26
11
Open key Encryption
• Encryption methods, which are based on the “secret
key” function have one, but significant disadvantage: it
is necessary to distribute a key among all users and all
of them must take care of keeping the key unavailable
to others.
• The alternative is an “open key” encryption, which
became very popular during last 15-20 years. In this
method, which is based on the modular arithmetic,
two different keys are used for encryption and
decryption. The encrypting key is a “public key”, it is
open, while the decrypting key is hidden.
12
RSA Encryption
• In “open key” encryption methods, it is
extremely hard (actually, it is impossible
within some reasonable long time interval) to
reverse a key, which is used for the
encryption.
• One of the most popular, efficient (and
simple!) modern “open key” encryption
methods is RSA named for its inventors
(Rivest, Shamir, Adleman).
13
Modular Exponentiation
• Modular exponentiation is a key operation in
the RSA encryption. It is raising of a number to
a power e in Zn:
a  b  mod n   0  a  n
e
• In the RSA method, both e and n are very large
numbers. In the real world applications, n is
an integer of about 400 decimal digits.
14
Modular Exponentiation
• To perform modular exponentiation,
congruence properties are used.
• To reduce computations, exponent e should
be presented as a sum of powers of 2 (any
integer number should be easily presented in
such a way:e  e1  e2  ...  ek ; ei  2s )
• Then the following technique should be
applied: be  be e ...e  be be ...be 
1
2
k
1
2
k
 be1 (mod n)  be2 (mod n)  ...  bek (mod n)
15
Modular Exponentiation
• For example, let b  90; e  101; n  1189
• Then
e  101  20  22  25  26  1  4  32  64
be  90101  901 43264  90  904  9032  9064 (mod1189) 
 90(mod1189)  (902 ) 2 (mod1189)  (90 2 )5 (mod1189)  (90 2 )6 (mod1189) 
 90  980 1125  529  88200 1125  529  240750  529  240750  529(mod1189) 
 240750(mod1189)  529(mod1189)  572  529(mod1189)  302588(mod1189)  582
16
RSA Encryption
• In the RSA encryption method, a message is
converted into numbers, as in the modular
encryption that we saw before.
• The letters are then put together into number
blocks with each block less than n.
• Then each number block is exponentiated by
the exponent e modulo n , which completes
the encryption procedure.
17
RSA Encryption
• In the RSA encryption method, n is chosen to be
the product of prime numbers.
• If n=pq, then e is chosen so that GCD (e, r) = 1,
where r= (p-1)(q-1). There are many such es
(almost all positive integers satisfy the given
condition).
• In the RSA decryption, the exponent d is chosen
as the smallest positive solution x to the
congruence ex 1 (mod r):
(b e (mod n ))d (mod n )= b
18
RSA Encryption
b e (mod n)
n = 4559, e = 13.
Smiley Transmits: “Last name Smiley”

19
RSA Encryption
b e (mod n)
n = 4559, e = 13.
Smiley Transmits: “Last name Smiley”
 L A S T
N AM E
S M I L

E Y
20
RSA Encryption
b e (mod n)

n = 4559, e = 13.
Smiley Transmits: “Last name Smiley”
 L A S T
N AM E
S M I L E Y
 1201 1920 0014 0113 0500 1913 0912 0525
21
RSA Encryption
b e (mod n)

n = 4559, e = 13.
Smiley Transmits: “Last name Smiley”
 L A S T
N AM E
S M I L E Y
 1201 1920 0014 0113 0500 1913 0912 0525
 120113 mod 4559, 192013 mod 4559, …
22
RSA Encryption
b e (mod n)

n = 4559, e = 13.
Smiley Transmits: “Last name Smiley”
 L A S T
N AM E
S M I L E Y
 1201 1920 0014 0113 0500 1913 0912 0525
 120113 mod 4559, 192013 mod 4559, …
 2853 0116 1478 2150 3906 4256 1445 2462
23
RSA Encryption
b e (mod n)

n = 4559, e = 13.
Smiley Transmits: “Last name Smiley”
 L A S T
N AM E
SM I L E Y
 1201 1920 0014 0113
0500 1913
0912 0525
 120113 mod 4559, 192013 mod 4559, …
 2853 0116 1478 2150 3906 4256 1445 2462
24
RSA Encryption
•
•
a private decryption exponent d ,which
when applied to n , recovers the original
blocks b : (b e mod n )d mod n = b
For n = 4559, e = 13 the decryptor d = 3397
25
Homework
• Read Sections 3.2 – 3.3
• Problems (Exercises 3.3) 1, 2.
26