CSC Information Systems Security Topic. Basic Number Theory CSC Dr. Peng Ning Basic Number Theory We are talking about integers! Divisor We say that b divides a if a = mb for some m, denoted b a. b is a divisor of a. If a, then a = or. If a b and b a, then a = b or b. Any b divides. If b g and b h, then b (mg+nh) for arbitrary integers m and n. CSC Dr. Peng Ning
Basic Number Theory (Cont d) Prime numbers An integer p > is a prime number if its only divisors are,, p, and p. Examples:,,,,,,,,, Any integer a > can be factored in a unique a way as a = p a p a...p t t where each p >p > >p t are prime numbers and where each a i >. Examples: =, =. CSC Dr. Peng Ning Basic Number Theory (Cont d) Another view of a b: Let P be the set of all prime numbers Represent a as Represent b as a b means that a i b i. a = " p #P p a p, where a p $. b = " p #P p b p, where b p $. CSC Dr. Peng Ning
Basic Number Theory (Cont d) Greatest common divisor: gcd(a,b) gcd(a,b) =max{k k a and k b} Examples gcd(,)=. gcd(,)=gcd(,-)=. gcd(a,) = a. gcd(a,b) can be easily derived if we can factor a and b. Relatively Prime Numbers Integers a and b are relatively prime if gcd(a,b) =. Example: 8 and are relatively prime. CSC Dr. Peng Ning Modulo Operator Given any positive integer n and any integer a, we have a = qn+r, where r<n and q= a/n. We write r = a mod n. The remainder r is often referred to as a residue. Example: = mod. Two integer a and b are said to be congruent modulo n if a mod n = b mod n. We write a b mod n Example: mod. CSC Dr. Peng Ning
Modulo Operator (Cont d) Properties of modulo operator a b mod n if n (a b) (a mod n) = (b mod n) implies a b mod n. a b mod n implies b a mod n. a b mod n and b c mod n imply a c mod n. CSC Dr. Peng Ning Modular Arithmetic Observation: The (mod n) operator maps all integers into the set of integers{,,,, (n-)}. Modular addition. [(a mod n) + (b mod n)] mod n = (a+b) mod n Modular subtraction. [(a mod n) (b mod n)] mod n = (a b) mod n Modular multiplication. [(a mod n) (b mod n)] mod n = (a b) mod n CSC Dr. Peng Ning 8
An Exercise (n=) Addition Multiplication Exponentiation mod = CSC Dr. Peng Ning Properties of Modular Arithmetic Z n ={,,, (n-)} Commutative laws (w + x) mod n = (x + w) mod n (w x) mod n = (x w) mod n Associative laws [(w + x) + y] mod n = [w + (x + y)] mod n [(w x) y] mod n = [w (x y)] mod n Distributive law [w (x + y)] mod n = [(w x)+(w y)] mod n Identities ( + w) mod n = w mod n ( w) mod n = w mod n Additive inverse ( w) For each w Z n, there exists a z such that w + z= mod n. CSC Dr. Peng Ning
About Multiplicative Inverse Not always exist Example: There doesn t exist a z such that z = mod 8. Z 8 Residues An integer a Z n has a multiplicative inverse if gcd(a, n) =. In particular, if n is a prime number, then all elements in Z n have multiplicative inverse. 8 CSC Dr. Peng Ning Fermat s Theorem If p is prime and a is a positive integer not divisible by p, then a p- mod p. Observation: {a mod p, a mod p,, (p-)a mod p} = {,,, (p-)}. a a.. (p-)a [(a mod p) (a mod p) ((p-)a mod p)] mod p (p-)! a p- (p-)! mod p Thus, a p- mod p. CSC Dr. Peng Ning
Totient Function Totient function ø(n): number of integers less than n and relatively prime to n If n is prime, ø(n)=n- If n=p q, and p, q are primes, ø(n)=(p-)(q-) Examples: ø()= ø()= CSC Dr. Peng Ning Euler s Theorem For every a and n that are relatively prime, a ø(n) mod n. Proof leaves as an exercise. Examples a=, n=, ø()=, ø() mod = a=, n=, ø()=, ø() mod =. CSC Dr. Peng Ning
Modular Exponentiation x y mod n = x y mod ø(n) mod n if y = mod ø(n) then x y mod n = x mod n Example: mod = CSC Dr. Peng Ning Euclid s Algorithm Observation gcd(a, b) = gcd(b, a mod b) Eulid (d, f), d > f >.. X d; Y f. If Y = return X=gcd(d, f). R = X mod Y. X Y. Y R. Goto CSC Dr. Peng Ning
Extended Euclid Algorithm Extended Euclid (d, f). (X, X, X) (,,f); (Y, Y, Y) (,,d). If Y= return X=gcd (d, f); no inverse. If Y= return Y=gcd (d, f); Y=d mod f. Q= X/Y. (T, T, T) (X QY, X QY, X QY). (X, X, X) (Y, Y, Y). (Y, Y, Y) (T, T, T) 8. Goto Observation fx + dx = X; fy + dy = Y If Y =, then fy + dy = Y = d mod f CSC Dr. Peng Ning The Power of An Integer Modulo n Consider the following expression a m mod n If a and n are relatively prime, then there is at least one integer m that satisfies the above equation. That is, the Euler s totient function φ(n). The least positive exponent m for which the above equation holds is referred to as: The order of a (mod n) The exponent to which a belongs (mod n) The length of the period generated by a. CSC Dr. Peng Ning 8
Understanding The Order of a (mod n) Powers of Integers Modulo a a a a a a a a 8 a a a a a a a a a a 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 CSC Dr. Peng Ning Observations in The Previous Table All sequences end in. The length of a sequence divides φ() = 8. Lengths:,,,,, 8. Some of the sequences are of length 8. The base integer a generates (via powers) all nonzero integers modulo. CSC Dr. Peng Ning
Primitive Root The highest possible order of a (mod n) is φ(n). Primitive root If the order of a (mod n) is φ(n), then a is referred to as a primitive root of n. The powers of a: a, a,, a n- are distinct (mod n) and are all relatively prime to n. For a prime number p, if a is a primitive root of p, then a, a,, a p- are all the distinct numbers mod p. CSC Dr. Peng Ning Discrete Logarithm Given a primitive root a for a prime number p: The expression b a i mod p, i (p-), produces the integers from to (p-). The exponent i is referred to as the index of b for the base a (mod p), denoted as ind a,p (b). ind a,p ()=, because a mod p =. ind a,p (a)=, because a mod p = a. Example: Integer is a primitive root of prime number Number 8 Index 8 Number 8 Index CSC Dr. Peng Ning
Discrete Logarithm (Cont d) Consider x=a ind a,p(x) mod p, y=a ind a,p(y) mod p, and xy=a ind a,p(xy) mod p, a ind a,p(xy) mod p = (a ind a,p(x) mod p)(a ind a,p(y) mod p) a ind a,p(xy) mod p = (a ind a,p(x)+inda,p(y) ) mod p By Euler s theorem: a z a q mod p iff z q mod φ(p). ind a,p (xy) = ind a,p (x)+ind a,p (y) mod φ(p). ind a,p (y r ) = [r ind a,p (y)] mod φ(p). Discrete logarithm mod p: index mod p. Computing a discrete logarithm mod a large prime number p is in general difficult Used as the basis of some public key cryptosystems. CSC Dr. Peng Ning