Homepage › Solution manuals › Ivan Niven › An Introduction to the Theory of Numbers › Exercise 2.9.4 (Modular square roots)
Exercise 2.9.4 (Modular square roots)
With the aid of a pocket calculator, use RESSOL to find solutions of the following congruences:
Answers
Proof.
- (a)
-
Here
and
. Note that
, where
. Starting from
we obtain
where , and .
We choose a generator quadratic non residue . Since , we take .
(Then is a generator of , and is a generator of the subgroup of elements whose order is a power of .)
The order of is . The order of is .
(Since , we verify anew that is a quadratic residue.)
Therefore and have the same order . Multiplying (1) by , we obtain
that is , where , and must have order , with . Indeed, .
Therefore , and is a square root of modulo . The other root is .
Verification: .
- (b)
- Similarly, for the equation , we obtain , and . Since , there is no loop, and the roots of modulo are .
- (c)
-
With
, we obtain
. No loop :
are the roots of
modulo
.
Note: in the cases (b) and (c), we have , thus the roots are given by .
- (d)
- With , we obtain , thus are the roots of modulo .
A Python code to implement the RESSOL algorithm is
from random import randint def legendre(a, p): resu = pow(a, (p - 1) // 2, p) if resu > p//2: resu -= p return resu def ressol(a, p): assert legendre(a, p) == 1, "not a square (mod p)" m = p - 1 s = 0 while m % 2 == 0: m //= 2 s += 1 found = False while not found: xi = randint(2, p - 2) if -1 == legendre(xi, p): found = True c = pow(xi, m , p) # o(c) = 2^s r = pow(a, (m+1) // 2, p) n = pow(a, m, p) while n!=1: i = 0 npower = n while npower != 1: npower = (npower * npower) % p i = i + 1 # o(n) = 2^i b = pow(c, 2 ** (s-i-1), p) # o(b^2) = 2^i = o(n) r = (r * b) % p n = (n * b * b) % p return(r) if __name__ == ’__main__’: print(ressol(43,97))