Number theory ------------- ------- Prime numbers Prime number Definition: An integer whose only factors are 1 and itself pi(n) is the number of primes inf) pi(n) / (n/ln n) = 1, so any large number n has about 1 in ln(n) chance of being prime. Prime factorization, AKA the Fundamental Theorem of Arithmetic All integers can be expressed as a product of (powers of) primes Eg., 48 = 2*2*2*3 = 2^3 * 3 Factorization is the process of finding the prime factors of a number. This is a relatively hard problem for large numbers. Notation a|b is read "a divides b". IE., a evenly divides b, or equivalently b*k=a for some integer k. GCD - the greatest common divisor (or greatest common factor) Definition: The largest number which divides two numbers gcd(15, 25) = 5 Relatively prime numbers Two numbers whose gcd is 1. (No common factors) ------- Modular math Notation % and (mod n). Congruence _ _ Equals with 3 bars. a = b (mod n) means that a%n = b%n The Modulus Simple exercies - multiplication, addition, congruence More notation The fancy Z means the set of integers Zn means the set of integers modulo n; [0,n-1]. Zn* is the multiplicative group of integers modulo n. Quite different from Zn. Multiplicative and additive inverses Additive inverses. In Z, the additive inverse of 3 is -3, since 3 + -3 = 0, the additive identity. In Zn, the additive inverse of a is n-a, since a-(n-a) = n, which is congruent to 0 (mod n). In Z, the multiplicative inverse of 3 is 1/3, since 3*1/3=1. The multiplicative identity in both Z and Zn is 1. The multiplicative inverse of 3 mod 10 is 7, since 7*3=21=1 (mod 10). This could be written 3^-1, or (rarely) 1/3. Distribution in + and * Modular arithmetic is distributive. That is, a+b (mod n) = (a mod n) + (b mod n) (mod n) This distributive property should be intuitive when you think that 1 o'clock pm plus 1 hour = 2pm, as does 1pm + 25 hours. Mathematically, it works because: Let a=cn+d. Then a%n=d, the remainder after taking out the multiples of n. Let b=en+f. Then f = b%n. a + b (mod n) = cn+d + en+f (mod n) but cn = en = 0 (mod n) (since c and e are multiples of n), so: = d + f (mod n) = a%n + b%n (mod n). The modulus also distributes into multiplication. Consider a*b%n. Let a=cn+d and b=en+f, just as before. a * b (mod n) = (cn+d) * (en+f) (mod n) = cnen + cnf + den + df (mod n) = (cen)n + (cf)n + (de)n + df (mod n) But any multiple of n modulo n is 0, so = 0 + 0 + 0 + df (mod n) = a%n * b%n (mod n) An example helps: 7 * 26 (mod 5) = (1*5 + 2) * (5*5 + 1) (mod 5) = 1*5*5*5 + 1*5*1 + 2*5*5 + 2*1 (mod 5) = 0 + 0 + 0 + 2*1 (mod 5) = 7%5 + 26%5 (mod 5) = 2 (mod 5) Modular exponentiation (See Lab 2 assignment on website for notes on modexp) ------------ Fermat's Little Theorem (and proof) Using Fermat to compute multiplicative inverses Fermat Primality test Euler's Generalization of Fermat's Little Theorem RSA: Key generation * Safe primes * calculating phi(n) and using phi(phi(n)) to calculate ed=1 (mod phi(n)) Encryption and decryption * Easy once you have the keys Signing * Using hashed documents Groups, rings and fields. * Properties of each --------------------------------------------------------