-- Apr 11 In-Class Exercise Thread
Solution from the Slides
Assumptions: a⋅b and amodb are computable in time proportional to ∣∣a∣∣⋅∣∣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≠1.
(
Edited: 2018-04-16)
<nowiki>
Solution from the Slides
Assumptions: a⋅b and amodb are computable in time proportional to ∣∣a∣∣⋅∣∣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≠1.
</nowiki>