Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 7– Introduction to Number Theory Instructor: 孫宏民 Room: EECS 6402, Tel:03- 5742968, Fax : 886-3-572-3694.

Similar presentations


Presentation on theme: "1 Chapter 7– Introduction to Number Theory Instructor: 孫宏民 Room: EECS 6402, Tel:03- 5742968, Fax : 886-3-572-3694."— Presentation transcript:

1 1 Chapter 7– Introduction to Number Theory Instructor: 孫宏民 hmsun@cs.nthu.edu.tw hmsun@cs.nthu.edu.tw Room: EECS 6402, Tel:03- 5742968, Fax : 886-3-572-3694

2 2 Prime Numbers prime numbers only have divisors of 1 and self –they cannot be written as a product of other numbers –note: 1 is prime, but is generally not of interest eg. 2,3,5,7 are prime, 4,6,8,9,10 are not prime numbers are central to number theory list of prime number less than 200 is: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199

3 3 Prime Factorisation to factor a number n is to write it as a product of other numbers: n=a × b × c note that factoring a number is relatively hard compared to multiplying the factors together to generate the number the prime factorisation of a number n is when its written as a product of primes –eg. 91=7×13 ; 3600=2 4 ×3 2 ×5 2

4 4 Relatively Prime Numbers & GCD two numbers a, b are relatively prime if have no common divisors apart from 1 –eg. 8 & 15 are relatively prime since factors of 8 are 1,2,4,8 and of 15 are 1,3,5,15 and 1 is the only common factor conversely can determine the greatest common divisor by comparing their prime factorizations and using least powers –eg. 300=2 1 ×3 1 ×5 2 18=2 1 ×3 2 hence GCD(18,300)=2 1 ×3 1 ×5 0 =6

5 5 Fermat's Theorem a p-1 mod p = 1 –where p is prime and gcd(a,p)=1 also known as Fermat’s Little Theorem useful in public key and primality testing

6 6 Euler Totient Function ø(n) when doing arithmetic modulo n complete set of residues is: 0..n-1 reduced set of residues is those numbers (residues) which are relatively prime to n –eg for n=10, –complete set of residues is {0,1,2,3,4,5,6,7,8,9} –reduced set of residues is {1,3,7,9} number of elements in reduced set of residues is called the Euler Totient Function ø(n)

7 7 Euler Totient Function ø(n) to compute ø(n) need to count number of elements to be excluded in general need prime factorization, but –for p (p prime) ø(p) = p-1 –for p.q (p,q prime) ø(p.q) = (p-1)(q-1) eg. –ø(37) = 36 –ø(21) = (3–1)×(7–1) = 2×6 = 12

8 8 Euler's Theorem a generalisation of Fermat's Theorem a ø(n) mod N = 1 –where gcd(a,N)=1 eg. –a=3;n=10; ø(10)=4; –hence 3 4 = 81 = 1 mod 10 –a=2;n=11; ø(11)=10; –hence 2 10 = 1024 = 1 mod 11

9 9 Primality Testing often need to find large prime numbers traditionally sieve using trial division –ie. divide by all numbers (primes) in turn less than the square root of the number –only works for small numbers alternatively can use statistical primality tests based on properties of primes –for which all primes numbers satisfy property –but some composite numbers, called pseudo-primes, also satisfy the property

10 10 Miller Rabin Algorithm a test based on Fermat’s Theorem algorithm is: TEST (n) is: 1. Find integers k, q, k > 0, q odd, so that (n–1)=2 k q 2. Select a random integer a, 1<a<n–1 3. if a q mod n = 1 then return (“maybe prime"); 4. for j = 0 to k – 1 do 5. if ( a 2 j q mod n = n-1 ) then return(" maybe prime ") 6. return ("composite")

11 11 Probabilistic Considerations if Miller-Rabin returns “composite” the number is definitely not prime otherwise is a prime or a pseudo-prime chance it detects a pseudo-prime is < ¼ hence if repeat test with different random a then chance n is prime after t tests is: –Pr(n prime after t tests) = 1-4 -t –eg. for t=10 this probability is > 0.99999

12 12 Prime Distribution prime number theorem states that primes occur roughly every ( ln n ) integers since can immediately ignore evens and multiples of 5, in practice only need test 0.4 ln(n) numbers of size n before locate a prime –note this is only the “average” sometimes primes are close together, at other times are quite far apart

13 13 Algebraic System Binary Operation: Given a nonempty set S and a function op : S×S  S, then op is a binary operation on S. Examples: S= N and op = × :the multiple of integer S= N and op = +: the addition of integer. Algebratic Systems: (S, op 1, op 2, …, op n ), where S is a nonenmpty set and there are at least one binary operation on S. Examples: (R, +, ×) and (Z, +, ×)

14 14 Properties of Algebratic Systems –Closure: a op b  S, where a and b  S. –Associative: (a op b) op c= a op (b op c) for (S, op), where a, b, and c  S. –Communicative: a op b = b op a for (S, op) for a and b  S. –(Z, -) have no communicative property. –Identity: For (S, op),  e  S,  a  S, such that a op e= e op a= a. –Example: For (Z, +), e=0, for (Z, ×), e= 1. –Inverses: For (S, op),  a  S,  b  S, such that a op b = b op a = e. –Symbol : a -1 or -a.

15 15 –Example: For (Z, +), the inverse of a is -a. –Example: For (R/{0}, ×), the inverse of a is a -1 while, for (Z, ×), there is no inverse for any integer. –Distribution: For (S, +, *), a*(b+c)= a*b+a*c, where a, b, and c  S. –Semigroup (G,*): An algebratic system (G, *) with the following properties: Closure, association, and an identity. –Theorem: For a semigroup (G, *), the identity is unique.

16 16 Groups (G, *) : A semigroup (G, *) with inverses. Examples:(Z, +), (R/{0}, *) are groups. Abelian (Commutative) Groups: the group with communitative property Theorem: For a group (G, *), the inverse of an element in G is unique. Field (F, +, *): (F, +) is a commutative group. (F, *) is a semigroup and (F-{0}, *) is a commutative group, where 0 is the identity for the operation +.

17 17 Finite Fields Finite Group (G, *): A group (G, *) with finite elements in G. Example: ({0, 1, …, N-1}, +N) is a finite group, where N is an integer. Cyclic Group (G, *): For a group (G, *), there exists an element a such that G= {an|n  Z}, where an =a*a* …*a (n-1 times). a:primitive root (with the order n=|G|). Example: ({1, …, 6}, *7) is a cyclic group with the primitive root 3. [{3, 2, 6, 4, 5, 1}, & order= 6]

18 18 Generator with order m: a m =1. Finite Fields: A field (F, +, *) with finite elements in F. Example:GF(P)= ({0, 1, …, P-1}, +P, *P) for a prime number P. [The first finite fields].

19 19 Some Famous Finite Fields [P is a prime number] GF(P) or ZP. GF(Pn): Given an irreducible polynomial Q(x) of degree n over GF(P). GF(2n) for P= 2. Example: Q(x)= x 3 +x+1 over GF(2) (x+1)+ (x)= 1. (x+1)*x 2 = x 2 +x+1.

20 20 Congruences Given integers a, b, and n  0, a, is congruent to b modulo n, written a  b mod n if and only if a  b = kn for some integer k. Ex. 41  93 mod13. 18  10 mod8.

21 21 If a  b mod n, then b is called a residue of a modulo n (conversely, a is a residue of b modulo n). A set of n integers {r 1, …, r n } is called a complete set of residues modulo n if, for every integer a, there is exactly one r i in the set such that a  r i mod n. For any modulus n, the set of integers {0, 1,…, n  1} forms a complete set of residues modulo n.

22 22 Computing Inverses Unlike ordinary integer arithmetic, modular arithmetic sometimes permits the computation of multiplicative inverse That is, given an integer a in the range [0, n  1], it may be possible to find a unique integer x in the range [0, n  1] such that ax mod n = 1. Ex. 3 and 7 are multiplicative inverses mod 10 because 21 mod 10 = 1. Thm. If gcd(a, n) = 1, then (ai mod n)  (aj mod n) for each i, j such that 0  i < j < n.

23 23 This property implies that each ai mod n (i = 0,..., n  1) is a distinct residue mod n, and that the set {ai mod n} i=0,..., n  1 is a permutation of the complete set of residues {0,..., n  1}. This property does not hold when a and n have a common factor. If gcd(a, n) = 1, then there exists an integer x, 0 < x < n, such that ax mod n = 1.

24 24 Ex. n = 5 and a = 3: 3  0 mod 5 = 0 3  1 mod 5 = 3 3  2 mod 5 = 1 3  3 mod 5 = 4 3  4 mod 5 = 2. Ex. n = 4 and a = 2: 2  0 mod 4 = 0 2  1 mod 4 = 2 2  2 mod 4 = 0 2  3 mod 4 = 2.

25 25 Solving for Inverse Euler's generalization of Fermat's theorem gives us an algorithm for solving the equation ax mod n = 1, where gcd(a, n) = 1. Since a  (n) mod n = 1, we may compute x as ax  a  (n), or x = a  (n)  1 mod n. If n is prime, this is simply x = a (n  1)  1 mod n = a n  2 mod n.

26 26 Ex. Let a = 3 and n = 7. Then x = 3 5 mod 7 = 5. Ex. Let a = 2 and n = 15. Then x = 2 7 mod 15 = 8. With this approach, to compute x, you have to know  (n).

27 27 Another Approach x can also be computed using an extension of Euclid's algorithm for computing the greatest common divisor. This is more suitable for computers to do. Euclid's algorithm for computing greatest common divisor : gcd(a, n) g 0  n g 1  a i  1 while g i  0 g i+1  g i  1 mod g i i  i + 1 return g i  1

28 28 Extended Euclid's Algorithm Extended Euclid's algorithm for computing inverse (loop invariant: g i = u i n + v i a): inv(a, n) g 0  n; g 1  a; u 0  1; v 0  0; u 1  0; v 1  1; i  1 while g i  0 y  g i  1 div g i g i+1  g i  1  y  g i u i+1  u i  1  y  u i v i+1  v i  1  y  v i i  i + 1 x  v i  1 if x  0 return x else return x + n

29 29 Example Ex. To solve 3x mod 7 = 1 using the algorithm, we have Because v 2 =  2 is negative, the solution is x =  2 + 7 = 5. igigi uiui vivi y 0710 13012 211 22 3 30

30 30 Chinese Remainder Theorem used to speed up modulo computations working modulo a product of numbers –eg. mod M = m 1 m 2..m k Chinese Remainder theorem lets us work in each moduli m i separately since computational cost is proportional to size, this is faster than working in the full modulus M

31 31 Chinese Remainder Theorem can implement CRT in several ways to compute (A mod M) can firstly compute all (a i mod m i ) separately and then combine results to get answer using:

32 32 Example Ex. Solve the equation "3x mod 10 = 1". Since 10 = 2  5, d 1 = 2 and d 2 = 5. We first find solutions x 1 and x 2, as follows: 3x mod 2 = 1 mod 2 = 1  x 1 = 1 3x mod 5 = 1 mod 5 = 1  x 2 = 2 Then we apply the Chinese Remainder Theorem to find a common solution x to the equations:

33 33 x mod 2 = x 1 = 1 x mod 5 = x 2 = 2. We find y 1 and y 2 satisfying (10/2) y 1 mod 2 = 1  y 1 = 1 (10/5) y 2 mod 5 = 1  y 2 = 3 Thus, we have x= ((10/2) y 1 x 1 + (10/5) y 2 x 2 ) mod 10 = (5  1  1 + 2  3  2) mod 10 = 7.

34 34 Primitive Roots from Euler’s theorem have a ø(n) mod n=1 consider a m mod n=1, GCD(a,n)=1 –must exist for m= ø(n) but may be smaller –once powers reach m, cycle will repeat if smallest is m= ø(n) then a is called a primitive root if p is prime, then successive powers of a "generate" the group mod p these are useful but relatively hard to find

35 35 Discrete Logarithms or Indices the inverse problem to exponentiation is to find the discrete logarithm of a number modulo p that is to find x where a x = b mod p written as x=log a b mod p or x=ind a,p (b) if a is a primitive root then always exists, otherwise may not –x = log 3 4 mod 13 (x st 3 x = 4 mod 13) has no answer –x = log 2 3 mod 13 = 4 by trying successive powers whilst exponentiation is relatively easy, finding discrete logarithms is generally a hard problem


Download ppt "1 Chapter 7– Introduction to Number Theory Instructor: 孫宏民 Room: EECS 6402, Tel:03- 5742968, Fax : 886-3-572-3694."

Similar presentations


Ads by Google