CS255
Chris Pollett
Apr 11, 2018
Witness(a,n) 1 let n - 1 = 2^t*u, where t >= 1 and u is odd 2 x_0 = Modular-Exponentiation(a, u, n) 3 for i = 1 to t: 4 x_i = (x_(i-1))^2 mod n 5 if x_i = 1 and x_(i-1) != 1 and x_(i-1) != n-1: 6 return true 7 if x_t != 1: 8 return true 9 return false
Miller-Rabin(n, s) 1 for j = 1 to s 2 a = Random(1, n - 1) 3 if Witness(a, n): 4 return "Composite" 5 return "Prime"
Theorem. If `n` is composite, then the number of witnesses to compositeness is at least `(n-1)/2`.
Proof. We show the number of non-witnesses is at most `(n-1)/2`. First, any non-witness must be in `ZZ_n^(star)` as it must satisfy `a^(n-1) equiv 1 mod n`, i.e., `a cdot a^(n-2) equiv 1 mod n`; thus, it has an inverse. So we know `gcd(a,n) | 1` and hence `gcd(a, n) = 1`. Next we show that all non-witnesses are contained in a proper subgroup of `ZZ_n^(star)`. This implies the Theorem. There two cases to consider:
Solution.
Assumptions: `a cdot b` and `a mod b` are computable in time proportional to `|a| \cdot |b|` (can do grade school algorithms).
Exp-Mod(a, x, n) c := (Exp-Mod(a, floor(x/2), n))^2 mod n if x is even return c; else return a * c mod n;
Using the algorithm we have:
Exp-Mod(3, 560, 561) = (Exp-Mod(3, 280, 561))^2 mod 561 = ((Exp-Mod(3, 140, 561))^2 mod 561)^2 mod 561 = (((Exp-Mod(3, 70, 561))^2 mod 561)^2 mod 561)^2 mod 561 = ((((Exp-Mod(3, 35, 561))^2 mod 561)^2 mod 561)^2 mod 561)^2 mod 561 Let c = Exp-Mod(3, 35, 561) then c= = 3 * (Exp-Mod(3, 17, 561))^2 mod 561 = 3 * (3 * (Exp-Mod(3, 8, 561))^2 mod 561)^2 mod 561 ... to save writing we note Exp-Mod(3, 8, 561) = 3^4 * 3^4 = 81*81 = 390 mod 561 = 3 * (3 * (390)^2 mod 561)^2 mod 561 = 3 * (207 mod 561) ^2 mod 561 = 78 mod 561 Plugging in for c in the above = ((((c)^2 mod 561)^2 mod 561)^2 mod 561)^2 mod 561 = (((474)^2 mod 561)^2 mod 561)^2 mod 561 = ((276)^2 mod 561)^2 mod 561 = 441^2 mod 561 = 375 mod 561.
Notice this isn't 1, but that's okay as `gcd(3, 561) = 3 ne 1`.