Modular Exponentiation
Modular Exponentiation
Problem 1:
Calculate the value of: 2320 mod 29.
exponent (23(exp-1)mod29)•23 (23(exp-1)mod29•23)mod29 Comment
2 23•23 = 529 529 mod 29 = 7
3 7•23 = 161 161 mod 29 = 16
4 16•23 = 368 368 mod 29 = 20
5 20•23 = 460 460 mod 29 = 25
6 25•23 = 575 575 mod 29 = 24
7 24•23 = 552 552 mod 29 = 1
8 1•23 = 23 23 mod 29 = 23
9 23•23 = 529 529 mod 29 = 7 Value is identical to 23•23 = 232.
10 7•23 = 161 16
11 16•23 = 368 20
12 20•23 = 460 25
13 25•23 = 575 24
14 24•23 = 552 1
15 1•23 = 23 23
16 23•23 = 529 7
17 7•23 = 161 16
18 16•23 = 368 20
19 20•23 = 460 25
20
20
ANSWER: 24
Please note that 23 = 171,615,583,134,458,634,923,895,201 (a 27-digit decimal integer), and that
2320 = (234•2316) = 20•7 mod 29 = 140 mod 29 = 24, bypassing the determination of the
values of 2317, 2318, and 2319.
Problem 2:
Calculate the value of: 23391 mod 55.
(23(exp-1) •23(exp/2))
exponent (23(exp/2)•23(exp/2)) Comment
mod 55
1 [special] 231 = 23 23 mod 55 = 23
2 23•23 = 529 529 mod 55 = 34
Continuing to square ad infinitum will
4 34•34 = 1156 1156 mod 55 = 1
not change the result.
8 1•1 = 1 1 mod 55 = 1
16 1•1 = 1 1 mod 55 = 1
32 1•1 = 1 1 mod 55 = 1
64 1•1 = 1 1 mod 55 = 1
128 1•1 = 1 1 mod 55 = 1
256 1•1 = 1 1 mod 55 = 1
512 1•1 = 1 1 mod 55 = 1
Note that 391 = 256 + 128 + 4 + 2 + 1
23 •23 •23 •23 •23
256 128 4 2 1
391
= 1•1•1•34•23 = 782 782 mod 55 = 12
391
Note that 23 = 2.7263642784296496195425150858433e+532 (390 multiplications resulting in the
Problem 3:
Calculate the value of: 31397 mod 55.
(31(exp/2)•31(exp/2)) mod 55
exponent (31(exp/2)•31(exp/2)) Comment
= 31exp mod 55
1 [special] 311 = 31 31 mod 55
2 31•31 = 961 961 mod 55 = 26
4 26•26 = 676 676 mod 55 = 16
8 16•16 = 256 256 mod 55 = 36
16 36•36 = 1,296 1,296 mod 55 = 31
32 31•31 = 961 961 mod 55 = 26
64 26•26 = 676 16 Note that (3164 mod 55) ≡ (314 mod 55)
128 16•16 = 256 36
256 36•36 = 1,296 31
512 31•31 = 961 26
Note that 397 = 256 + 128 + 8 + 4 + 1
31•36•36•16•31 = (1116 mod 55)•36•16•31 = 16•36•16•31 = (576 mod 55) •16•31