3.9 Square Roots Mod n

Suppose we are told that x271(mod77) has a solution. How do we find one solution, and how do we find all solutions? More generally, consider the problem of finding all solutions of x2b(modn),  where n=pq is the product of two primes. We show in the following that this can be done quite easily, once the factorization of n is known. Conversely, if we know all solutions, then it is easy to factor n.

Let’s start with the case of square roots mod a prime p. The easiest case is when p3(mod4),  and this suffices for our purposes. The case when p1(mod4) is more difficult. See [Cohen, pp. 31–34] or [KraftW, p. 317].

Proposition

Let p3(mod4) be prime and let y be an integer. Let xy(p+1)/4(modp).

  1. If y has a square root mod p,  then the square roots of y mod p are ±x.

  2. If y has no square root mod p,  then y has a square root mod p,  and the square roots of y are ±x.

Proof. If y0(modp),  all the statements are trivial, so assume y0(modp). Fermat’s theorem says that yp11(modp). Therefore,

x4yp+1y2yp1y2(modp).

This implies that (x2+y)(x2y)0(modp),  so x2±y(modp). (See Exercise 13(a).) Therefore, at least one of y and y is a square mod p. Suppose both y and y are squares mod p,  say ya2 and yb2. Then 1(a/b)2 (work with fractions mod p as in Section 3.3), which means 1 is a square mod p. This is impossible when p3(mod4) (see Exercise 26). Therefore, exactly one of y and y has a square root mod p. If y has a square root mod p then yx2,  and the two square roots of y are ±x. If y has a square root, then x2y.

Example

Let’s find the square root of 5 mod 11. Since (p+1)/4=3,  we compute x534(mod11). Since 425(mod11),  the square roots of 5 mod 11 are ±4.

Now let’s try to find a square root of 2 mod 11. Since (p+1)/4=3,  we compute 238(mod11). But 8292(mod11),  so we have found a square root of 2 rather than of 2. This is because 2 has no square root mod 11.

We now consider square roots for a composite modulus. Note that

x271(mod77)

means that

x2711(mod7) and x2715(mod11).

Therefore,

x±1(mod7) and x±4(mod11).

The Chinese remainder theorem tells us that a congruence mod 7 and a congruence mod 11 can be recombined into a congruence mod 77. For example, if x1(mod7) and x4(mod11),  then x15(mod77). In this way, we can recombine in four ways to get the solutions

x±15, ±29(mod77).

Now let’s turn things around. Suppose n=pq is the product of two primes and we know the four solutions x±a, ±b of x2y(modn). From the construction just used above, we know that ab(modp) and ab(modq) (or the same congruences with p and q switched). Therefore, p|(ab) but q(ab). This means that gcd(ab, n)=p,  so we have found a nontrivial factor of n (this is essentially the Basic Factorization Principle of Section 9.4).

For example, in the preceding example we know that 15229271(mod77). Therefore, gcd(1529, 77)=7 gives a nontrivial factor of 77.

Another example of computing square roots mod n is given in Section 18.1.

Notice that all the operations used above are fast, with the exception of factoring n. In particular, the Chinese remainder theorem calculation can be done quickly. So can the computation of the gcd. The modular exponentiations needed to compute square roots mod p and mod q can be done quickly using successive squaring. Therefore, we can state the following principle:

Suppose n=pq is the product of two primes congruent to 3 mod 4, and suppose y is a number relatively prime to n that has a square root mod n. Then finding the four solutions x±a, ±b to x2y(modn) is computationally equivalent to factoring n.

In other words, if we can find the solutions, then we can easily factor n; conversely, if we can factor n,  we can easily find the solutions. For more on this, see Section 9.4.

Now suppose someone has a machine that can find single square roots mod n. That is, if we give the machine a number y that has a square root mod n,  then the machine returns one solution of x2y(modn). We can use this machine to factor n as follows: Choose a random integer x1(modn),  compute yx12(modn),  and give the machine y. The machine returns x with x2y(modn). If our choice of x1 is truly random, then the machine has no way of knowing the value of x1,  hence it does not know whether xx1(modn) or not, even if it knows all four square roots of y. So half of the time, x±x1(modn),  but half of the time, x±x1(modn). In the latter case, we compute gcd(xx1, n) and obtain a nontrivial factor of n. Since there is a 50% chance of success for each time we choose x1,  if we choose several random values of x1,  then it is very likely that we will eventually factor n. Therefore, we conclude that any machine that can find single square roots mod n can be used, with high probability, to factor n.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset