1. Discrete Logarithms in GF(p)
p
x where ax = b mod p
p is prime, then there always exists some
a for which there is always a discrete logarithm for
any b!=0
a "generate" the group mod p
a is called a primitive root
2. Greatest Common Divisor
(a,b) of a and b
is the largest number that divides evenly into both a and b
3. Euclid's GCD Algorithm
a and n, given a<n
a and b have divisor
d then so does a-b, a-2b, ...
GCD (a,n) is given by:
let g0=n
g1=a
gi+1 = gi-1 mod gi
when gi=0 then (a,n) = gi-1
4. GCD Example
g0=98 g1=56 g2 = 98 mod 56 = 42 g3 = 56 mod 42 = 14 g4 = 42 mod 14 = 0 hence (56,98)=14
5. Inverses and Euclid's Extended GCD Routine
a-1 is inverse of a mod n if
a.a-1 = 1 mod n,
where a,x in {0,n-1}
3.7 = 1 mod 10
GCD(a,n)=1 then the inverse always exists
gi = ui.n + vi.a
GCD(a,n)=1 will find
1 = ui.n + vi.a giving us the inverse
6. Extended Euclid's Algorithm to find Inverses
a mod n (where (a,n)=1)
Inverse(a,n) is given by:
g0=n u0=1 v0=0
g1=a u1=0 v1=1
loop computing
y = gi-1 div gi
gi+1 = gi-1 - y.gi = gi-1 mod gi
ui+1 = ui-1 - y.ui
vi+1 = vi-1 - y.vi
until gi=0
at end Inverse(a,n) = vi-1
7. Inverse Calculation Example
i y g u v 0 - 460 1 0 1 - 3 0 1 2 153 1 1 -153 3 3 0 -3 460 hence Inverse(3,460) = -153 = 307 mod 460
8. Inverse Calculation Example
i y g u v Difference Equation tracked 0 - 323 1 0 323 = 1.323 + 0.299 1 - 299 0 1 299 = 0.323 + 1.299 2 1 24 1 -1 24 = 1.323 + -1.299 3 12 11 -12 13 11 = -12.323 + 13.299 4 2 2 25 -27 2 = 25.323 + -27.299 5 5 1 -137 148 1 = -137.323 + 148.299 *** answer *** ie 148.299 = 137.323 + 1 = 1 mod 323 gives 148 as inverse of 299 mod 323
9. Euler Totient Function ø(n)
0..n-1
10. Formulae for the Euler Totient Function ø(n)
p (p prime) ø(p) = p-1 pr (p prime) ø(p) = pr-1(p-1) p.q (p,q prime) ø(p.q) = (p-1)(q-1)
11. Fermat's and Euler's Theorems
ap-1 mod p = 1
aø(n) mod n = 1
12. Ways of Computing Inverses
a-1 mod n
a-1 is found with
a.a-1 = 1 mod n
ø(n) is known, then from Euler's Theorem have
a-1 = aø(n)-1 mod n
13. Primality Testing
an-1 = 1 mod n where GCD(a,n)=1
14. Primality Testing
(a) (-) (mod n) = a (n-1)/2 (mod n) (n) where (a) (-) is the Jacobi function of a,n (n)
15. Chinese Remainder Theorem
M mod N
M1 mod p and
M2 mod q and combine results to get answer
M = [((M2 +q - M1)u mod q] p + M1 where p.u mod q = 1
16. Summary
17. Exercises
2x = 3 mod 5 4x = 3 mod 7 4x = 2 mod 13 5x = 3 mod 7 6x = 10 mod 11 7x = 3 mod 13 8x = 3 mod 11 9x = 6 mod 11
GCD(65,91) GCD(102,238) GCD(110,154) GCD(171,285) GCD(185,259)
57 61 65 79 83 85
2 mod 11 2 mod 15 5 mod 7 5 mod 17 12 mod 35 13 mod 45 17 mod 199 19 mod 193 21 mod 197 22 mod 199