Suppose we are told that 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 where is the product of two primes. We show in the following that this can be done quite easily, once the factorization of is known. Conversely, if we know all solutions, then it is easy to factor
Let’s start with the case of square roots mod a prime The easiest case is when and this suffices for our purposes. The case when is more difficult. See [Cohen, pp. 31–34] or [KraftW, p. 317].
Let be prime and let be an integer. Let
If has a square root mod then the square roots of mod are
If has no square root mod then has a square root mod and the square roots of are
Proof. If all the statements are trivial, so assume Fermat’s theorem says that Therefore,
This implies that so (See Exercise 13(a).) Therefore, at least one of and is a square mod Suppose both and are squares mod say and Then (work with fractions mod as in Section 3.3), which means is a square mod This is impossible when (see Exercise 26). Therefore, exactly one of and has a square root mod If has a square root mod then and the two square roots of are If has a square root, then
Let’s find the square root of 5 mod 11. Since we compute Since the square roots of 5 mod 11 are
Now let’s try to find a square root of 2 mod 11. Since we compute But so we have found a square root of 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
means that
Therefore,
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 and then In this way, we can recombine in four ways to get the solutions
Now let’s turn things around. Suppose is the product of two primes and we know the four solutions of From the construction just used above, we know that and (or the same congruences with and switched). Therefore, but This means that so we have found a nontrivial factor of (this is essentially the Basic Factorization Principle of Section 9.4).
For example, in the preceding example we know that Therefore, gives a nontrivial factor of 77.
Another example of computing square roots mod is given in Section 18.1.
Notice that all the operations used above are fast, with the exception of factoring 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 and mod can be done quickly using successive squaring. Therefore, we can state the following principle:
Suppose is the product of two primes congruent to 3 mod 4, and suppose is a number relatively prime to that has a square root mod Then finding the four solutions to is computationally equivalent to factoring
In other words, if we can find the solutions, then we can easily factor conversely, if we can factor 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 That is, if we give the machine a number that has a square root mod then the machine returns one solution of We can use this machine to factor as follows: Choose a random integer compute and give the machine The machine returns with If our choice of is truly random, then the machine has no way of knowing the value of hence it does not know whether or not, even if it knows all four square roots of So half of the time, but half of the time, In the latter case, we compute and obtain a nontrivial factor of Since there is a 50% chance of success for each time we choose if we choose several random values of then it is very likely that we will eventually factor Therefore, we conclude that any machine that can find single square roots mod can be used, with high probability, to factor