Modular exponentiation and fast powering - Discrete Math

  1. In a Diffie-Hellman key exchange with prime p=23p = 23 and generator g=5g = 5, Alice chooses secret a=8a = 8 and must compute ga mod p=58 mod 23g^a \bmod p = 5^8 \bmod 23. Using repeated squaring, what intermediate values will Alice compute?
    Answer: 51=5,52=2,54=4,58=165^1 = 5, 5^2 = 2, 5^4 = 4, 5^8 = 16 Computing powers of 5 modulo 23 using repeated squaring: 51=55^1 = 5. 52=25=23+2≡2(mod23)5^2 = 25 = 23 + 2 \equiv 2 \pmod{23}. 54=(52)2≡22=4(mod23)5^4 = (5^2)^2 \equiv 2^2 = 4 \pmod{23}. 58=(54)2≡42=16(mod23)5^8 = (5^4)^2 \equiv 4^2 = 16 \pmod{23}. Option B incorrectly shows 52=255^2 = 25 without reducing modulo 23. Option C has the wrong final value 58=95^8 = 9. Option D has incorrect intermediate values 54=65^4 = 6 and 58=135^8 = 13.
  2. Irene wants to compute 21000 mod 10012^{1000} \bmod 1001 efficiently. She discovers that 1001=7×11×131001 = 7 \times 11 \times 13 and uses the Chinese Remainder Theorem. If she finds 21000≡1(mod7)2^{1000} \equiv 1 \pmod{7}, 21000≡1(mod11)2^{1000} \equiv 1 \pmod{11}, and 21000≡1(mod13)2^{1000} \equiv 1 \pmod{13}, but then realizes she made an error in one calculation, which of these is most likely incorrect?
    Answer: 21000≡1(mod13)2^{1000} \equiv 1 \pmod{13} because 212≡1(mod13)2^{12} \equiv 1 \pmod{13} and 12∣100012 \mid 1000 By Fermat's Little Theorem: For mod 7: 26≡1(mod7)2^6 \equiv 1 \pmod{7}, and since 1000=166×6+41000 = 166 \times 6 + 4, we get 21000≡24≡16≡2(mod7)2^{1000} \equiv 2^4 \equiv 16 \equiv 2 \pmod{7}, not 1. For mod 11: 210≡1(mod11)2^{10} \equiv 1 \pmod{11}, and since 1000=100×101000 = 100 \times 10, we get 21000≡1(mod11)2^{1000} \equiv 1 \pmod{11}. For mod 13: 212≡1(mod13)2^{12} \equiv 1 \pmod{13}, but 1000=83×12+41000 = 83 \times 12 + 4, so 21000≡24≡16≡3(mod13)2^{1000} \equiv 2^4 \equiv 16 \equiv 3 \pmod{13}, not 1. The error in choice C is that 12 does not divide 1000 (since 1000=83×12+41000 = 83 \times 12 + 4). Choice A has the right reasoning but wrong conclusion. Choice B is actually correct. Choice D is wrong since not all are correct.
  3. A cryptographic protocol requires computing gab mod pg^{ab} \bmod p where aa and bb are secret values, gg is a generator, and pp is a large prime. Two approaches are suggested: (1) Compute ga mod pg^a \bmod p, then raise this result to the power bb; (2) Compute gab mod (p−1) mod pg^{ab \bmod (p-1)} \bmod p directly. Under what condition are these approaches equivalent?
    Answer: Always equivalent when pp is prime and gg is a generator Both approaches are mathematically equivalent when pp is prime and gcd⁡(g,p)=1\gcd(g,p) = 1. Method 1: (ga)b=gab(g^a)^b = g^{ab}. Method 2: By Fermat's Little Theorem, gp−1≡1(modp)g^{p-1} \equiv 1 \pmod{p}, so gab≡gab mod (p−1)(modp)g^{ab} \equiv g^{ab \bmod (p-1)} \pmod{p}. Since gg is a generator of the multiplicative group mod pp, we have gcd⁡(g,p)=1\gcd(g,p) = 1, so FLT applies. The results are identical. Option B is wrong - we need gcd⁡(g,p)=1\gcd(g,p) = 1, not gcd⁡(g,p−1)=1\gcd(g,p-1) = 1. Option C is wrong - the equivalence holds for any values of a,ba,b. Option D is wrong - they're mathematically equivalent regardless of computational differences.
  4. To compute 3100 mod 73^{100} \bmod 7 efficiently, Alice uses repeated squaring. She observes that 34≡4(mod7)3^4 \equiv 4 \pmod{7}. Using this observation and the binary representation 100=64+32+4100 = 64 + 32 + 4, what is the value of 3100 mod 73^{100} \bmod 7?
    Answer: 44 Since 100=64+32+4=26+25+22100 = 64 + 32 + 4 = 2^6 + 2^5 + 2^2, we have 3100=364⋅332⋅343^{100} = 3^{64} \cdot 3^{32} \cdot 3^4. Given 34≡4(mod7)3^4 \equiv 4 \pmod{7}, we compute: 38≡42≡16≡2(mod7)3^8 \equiv 4^2 \equiv 16 \equiv 2 \pmod{7}, 316≡22≡4(mod7)3^{16} \equiv 2^2 \equiv 4 \pmod{7}, 332≡42≡2(mod7)3^{32} \equiv 4^2 \equiv 2 \pmod{7}, 364≡22≡4(mod7)3^{64} \equiv 2^2 \equiv 4 \pmod{7}. Therefore 3100≡4⋅2⋅4≡32≡4(mod7)3^{100} \equiv 4 \cdot 2 \cdot 4 \equiv 32 \equiv 4 \pmod{7}. Choice A results from incorrectly applying Fermat's Little Theorem. Choice B comes from computational errors in the squaring process. Choice D results from missing the final reduction modulo 7.
  5. To compute 31000 mod 73^{1000} \bmod 7 efficiently, a student uses the fact that 36≡1(mod7)3^6 \equiv 1 \pmod{7} by Fermat's Little Theorem. However, the student makes an error and computes 1000 mod 7=61000 \bmod 7 = 6, concluding that 31000≡36≡1(mod7)3^{1000} \equiv 3^6 \equiv 1 \pmod{7}. What is the correct answer and what was the student's error?
    Answer: Correct answer is 34≡4(mod7)3^4 \equiv 4 \pmod{7}; student should have used 1000 mod 61000 \bmod 6 The student's error is using 1000 mod 71000 \bmod 7 instead of 1000 mod 61000 \bmod 6. Since 36≡1(mod7)3^6 \equiv 1 \pmod{7}, we need 1000 mod (6)=1000 mod 61000 \bmod (6) = 1000 \bmod 6. We have 1000=166×6+41000 = 166 \times 6 + 4, so 1000≡4(mod6)1000 \equiv 4 \pmod{6}. Therefore 31000≡34(mod7)3^{1000} \equiv 3^4 \pmod{7}. Now 32=9≡2(mod7)3^2 = 9 \equiv 2 \pmod{7} and 34=(32)2≡22=4(mod7)3^4 = (3^2)^2 \equiv 2^2 = 4 \pmod{7}. So the correct answer is 34≡4(mod7)3^4 \equiv 4 \pmod{7}. The key insight is that when using aϕ(n)≡1(modn)a^{\phi(n)} \equiv 1 \pmod{n}, we reduce the exponent modulo ϕ(n)\phi(n), not modulo nn.
  6. For the computation 32100 mod 1013^{2^{100}} \bmod 101, a student wants to use Fermat's Little Theorem since 101 is prime. They need to reduce the exponent 21002^{100} modulo 100. However, 21002^{100} is astronomically large. What is the most efficient approach to find 2100 mod 1002^{100} \bmod 100?
    Answer: Factor 100=4×25100 = 4 \times 25, note 2100≡0(mod4)2^{100} \equiv 0 \pmod{4}, and apply CRT with modulo 25 Since 100=4×25100 = 4 \times 25 and gcd⁡(4,25)=1\gcd(4,25) = 1, we can use the Chinese Remainder Theorem. For mod 4: 2100=(22)50=450≡0(mod4)2^{100} = (2^2)^{50} = 4^{50} \equiv 0 \pmod{4}. For mod 25: Since gcd⁡(2,25)=1\gcd(2,25) = 1 and ϕ(25)=20\phi(25) = 20, we have 220≡1(mod25)2^{20} \equiv 1 \pmod{25}. Therefore 2100=(220)5≡15=1(mod25)2^{100} = (2^{20})^5 \equiv 1^5 = 1 \pmod{25}. By CRT, we need x≡0(mod4)x \equiv 0 \pmod{4} and x≡1(mod25)x \equiv 1 \pmod{25}. Solving: x=25k+1x = 25k + 1 where 25k+1≡0(mod4)25k + 1 \equiv 0 \pmod{4}, so k+1≡0(mod4)k + 1 \equiv 0 \pmod{4}, giving k=3k = 3, thus x=76x = 76. Option A fails because Euler's theorem requires gcd⁡(2,100)=1\gcd(2,100) = 1, but gcd⁡(2,100)=2≠1\gcd(2,100) = 2 \neq 1.
  7. In RSA decryption, to compute cd mod nc^d \bmod n where d=157d = 157 and n=323=17×19n = 323 = 17 \times 19, a student decides to use Euler's theorem to reduce the exponent first. What is the reduced exponent that should be used?
    Answer: 157 mod 288=157157 \bmod 288 = 157 For RSA with n=p×qn = p \times q where pp and qq are distinct primes, we use ϕ(n)=(p−1)(q−1)\phi(n) = (p-1)(q-1). Here ϕ(323)=ϕ(17×19)=(17−1)(19−1)=16×18=288\phi(323) = \phi(17 \times 19) = (17-1)(19-1) = 16 \times 18 = 288. By Euler's theorem, if gcd⁡(c,323)=1\gcd(c,323) = 1, then c288≡1(mod323)c^{288} \equiv 1 \pmod{323}. Therefore, c157≡c157 mod 288(mod323)c^{157} \equiv c^{157 \bmod 288} \pmod{323}. Since 157<288157 < 288, we have 157 mod 288=157157 \bmod 288 = 157. The other options use incorrect values: 272 = 16×17 (wrong formula), 306 = 17×18 (another wrong formula), 324 = 18×18 (wrong formula).
  8. In RSA encryption with modulus n=77=7×11n = 77 = 7 \times 11, the public exponent is e=13e = 13. To decrypt a message, David needs to compute d≡e−1(modϕ(77))d \equiv e^{-1} \pmod{\phi(77)}. Using the extended Euclidean algorithm, he finds that 13×37+60×(−8)=113 \times 37 + 60 \times (-8) = 1. What is the correct private exponent dd?
    Answer: 3737 We have ϕ(77)=ϕ(7×11)=(7−1)(11−1)=6×10=60\phi(77) = \phi(7 \times 11) = (7-1)(11-1) = 6 \times 10 = 60. The equation 13×37+60×(−8)=113 \times 37 + 60 \times (-8) = 1 shows that 13×37≡1(mod60)13 \times 37 \equiv 1 \pmod{60}, so d=37d = 37. We can verify: 13×37=481=8×60+1≡1(mod60)13 \times 37 = 481 = 8 \times 60 + 1 \equiv 1 \pmod{60}. Choice B (52) comes from incorrectly computing 60−8=5260 - 8 = 52. Choice C (25) results from computational errors in the extended Euclidean algorithm. Choice D (13) represents the misconception that d=ed = e.
  9. A student computing 11123 mod 3511^{123} \bmod 35 decides to use the Chinese Remainder Theorem since 35=5×735 = 5 \times 7. They correctly find 11123≡1(mod5)11^{123} \equiv 1 \pmod{5} and 11123≡4(mod7)11^{123} \equiv 4 \pmod{7}. To combine these using CRT, what equation must they solve?
    Answer: Find xx such that x≡1(mod5)x \equiv 1 \pmod{5} and x≡4(mod7)x \equiv 4 \pmod{7} When applying the Chinese Remainder Theorem (CRT), you're reconstructing a number from its remainders modulo coprime factors. Since 35=5×735 = 5 \times 7 and gcd⁡(5,7)=1\gcd(5,7) = 1, you can find 11123 mod 3511^{123} \bmod 35 by combining the individual congruences. The key insight is that you must preserve each congruence exactly as computed. Since the student found 11123≡1(mod5)11^{123} \equiv 1 \pmod{5} and 11123≡4(mod7)11^{123} \equiv 4 \pmod{7}, the CRT system becomes: find xx such that x≡1(mod5)x \equiv 1 \pmod{5} and x≡4(mod7)x \equiv 4 \pmod{7}. This is answer choice C. Answer A switches the moduli incorrectly, giving x≡1(mod7)x \equiv 1 \pmod{7} and x≡4(mod5)x \equiv 4 \pmod{5} — this would solve a different problem entirely. Answer B makes the same error, just written in different order. Both A and B represent the common mistake of mixing up which remainder goes with which modulus. Answer D is nonsensical, presenting x≡5(mod1)x \equiv 5 \pmod{1} and x≡7(mod4)x \equiv 7 \pmod{4}. Since every integer is congruent to 0 modulo 1, the first congruence is impossible, and neither congruence relates to our original problem. Study tip: When setting up CRT systems, always match each remainder with its original modulus. Write down the congruences immediately after computing them to avoid mix-ups. The format is always "x≡(remainder)(modoriginal modulus)x \equiv (\text{remainder}) \pmod{\text{original modulus}}" for each piece.
  10. To optimize the computation of a65537 mod na^{65537} \bmod n (a common RSA public exponent), a programmer notes that 65537=216+165537 = 2^{16} + 1. This means the binary representation has exactly two 1-bits. What is the minimum number of modular multiplications required using this insight?
    Answer: 17 multiplications: 16 to compute a216a^{2^{16}} plus 1 to multiply by aa When you encounter modular exponentiation problems, especially with large exponents, think about how the binary representation of the exponent can optimize your computation strategy. The key insight here is that 65537=216+165537 = 2^{16} + 1, which has binary representation 10000000000000001210000000000000001_2 — exactly two 1-bits. To compute a65537 mod na^{65537} \bmod n efficiently, you need to break this into a216⋅a1 mod na^{2^{16}} \cdot a^1 \bmod n. First, compute a216a^{2^{16}} using repeated squaring: start with aa, then square it 16 times to get a2,a4,a8,…,a216a^2, a^4, a^8, \ldots, a^{2^{16}}. This requires exactly 16 multiplications. Then multiply this result by aa to get a216⋅a=a65537a^{2^{16}} \cdot a = a^{65537}, requiring 1 additional multiplication. Total: 17 multiplications. Option A misunderstands the optimization entirely — naive repeated multiplication would actually require 65,536 multiplications, not 32. Option B correctly identifies that standard repeated squaring for a general 17-bit number would need 16 squaring operations, but fails to account for the final multiplication step required when the exponent isn't a pure power of 2. Option D makes a conceptual error by claiming you only need 1 multiplication, ignoring that you must first compute a216a^{2^{16}} before you can multiply it by aa. The correct answer is C: 17 multiplications total. Study tip: When optimizing modular exponentiation, count every operation carefully. The binary method requires one multiplication per 1-bit in the exponent's binary representation, plus squaring operations to build the necessary powers.

Start this quiz