Professional Documents
Culture Documents
An RSA example
Let p = 47, q = 71, then n = pq = 3337.
Encryption key e must have no factors in common with
(p 1)(q 1) = 46 70 = 3220 .
Choose e = 79 (randomly).
Compute d = 791 mod 3220 = 1019 (with extended Euclidean
algorithm).
Publish e and n, keep d secret, discard p and q.
Break message m into small blocks, e.g., m = 688 232 687 966 668.
First block encrypted as 68879 mod 3337 = 1570 = c1.
To decrypt: 15701019 mod 3337 = 688 = m1.
60 = 4 14 + 4
14 = 3 4 + 2
4 = 22
Euclids Algorithm
Euclids algorithm is based on the theorem
gcd(a, b) = gcd(b, a mod b) for any nonnegative integer a and
any positive integer b.
For example, gcd(55, 22) = gcd(22, 55 mod 22) = gcd(22, 11) = 11.
The algorithm is
Euclid(a, b)
1 if b = 0
2 then return a
3 else return Euclid(b, a mod b)
Euclid(30, 21) = Euclid(21, 9) = Euclid(9, 3) = Euclid(3, 0) = 3.
a
99
78
21
15
6
3
b
78
21
15
6
3
0
a/b
1
3
1
2
2
d
3
3
3
3
3
3
x
11
3
2
1
0
1
y
14
11
3
2
1
0
an1 n 1
Example: 46 mod 7 = 16 16 16 mod 7 = 2 2 2 mod 7 = 1.
(1) = 1.
If p is a prime number, then (p) = p 1.
So that Fermats little theorem (for a and n relatively prime and
n prime) can be rewritten to
a(n) n 1
For two prime numbers p and q such that p = q and n = p q,
(n) = (p q) = (p) (q) = (p 1) (q 1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
n
(n) 1 1 2 2 4 2 6 4 6 4 10 4 12 6 8
Fast Exponentiation
There is an ecient algorithm (cf. the literature!) for computing
powers modulo n in a monoid G = (H, , e) (where H is a set,
is an associative operation on H, and e H is a neutral element
such that e a = a e = a for all a H).
Let g G and e be a positive integer with binary expansion
e=
k
k
g e = g i=0 ei2 =
following idea:
k
i=0(g
2 i ei
) =
0ik, ei=1 g
2i
yields the
i+1
i=0
Then
ge = g
k
i=0 ei 2
k
(g 2 )ei =
i=0
g2
0ik, ei=1
Fermat Test
2340 341 1
3340 341 56
N.B.:
if the Fermat Test proves that n is composite, it does not nd a divisor of n. It only
shows that n lacks a property that all prime numbers have. Therefore, the Fermat Test cannot be
used as a factoring algorithm.