Cryptology 2
Spring 2003
Modular Arithmetic and Quadratic Equations
How does one determine the solvability and the solutions of an equation such as
a*x2 + b*x + c mod R = 0
in NR?
The problem boils down to the question: Which nonzero residues mod R have square roots mod R? That is, for which a in NR are there x in NR such that
x2 mod R = a?
The following two definitions apply only to nonzero elements of NR: If a is a nonzero residue mod R which has a square root mod R, then a is said to be a quadratic residue mod R; otherwise, a is said to be a non-quadratic residue mod R (textbooks often say quadratic non-residue instead of non-quadratic residue).
It is always the case that 1 is a quadratic residue mod R; the main interest is in determining if there are any others.
Examples:
|
R |
Quadratic Residues |
Non-quadratic Residues |
|
4 |
1 |
2, 3 |
|
5 |
1, 4 |
2, 3 |
|
9 |
1, 4, 7 |
2, 3, 5, 6, 8 |
|
15 |
1, 4, 6, 9, 10, |
2, 3, 5, 7, 8, 11, 12, 13, 14 |
The following theorems provide us with computational tools to determine if for odd prime number P, a given number in NP has a square root mod P.
Theorem (Euler) Let P be an odd prime number and let a be a nonzero number in NP. Then
a(p-1)/2 mod P = 1, or a(p-1)/2 mod P = P-1. (Recall that in NP, -1 is the same thing as P-1.)
Theorem (Euler's Criterion): Let P be an odd prime number and let a be a nonzero number in NP. Then the following are equivalent:
Hence we can also conclude that a is a nonquadratic residue if, and only if, a(p-1)/2 mod P = P-1.
The quantity a(p-1)/2 mod P is denoted by a special symbol, called the Legendre symbol, which is
(a/P) := a(p-1)/2 mod P.
The Legendre symbol has the following properties which are quite useful in computing whether one number is a quadratic residue modulo another, which is an odd prime:
Theorem: Let P be an odd prime number and let a and b be nonzero elements of NP. Then:
From item 3 in the last theorem one gleans:
Corollary: Let P be an odd prime number. Then
Moreover, there are for a given odd prime number P as many quadratic residues mod P as there are non-quadratic residues mod P:
Theorem: For an odd prime number P, there are (P-1)/2 quadratic residues mod P, and there are (P-1)/2 non-quadratic residues mod P.
The following important theorem is due to Gauss:
Theorem (Gauss): If P is an odd prime number, then (2/P) is equal to (-1) raised to the power (P2-1)/8.
The deepest of the results regarding quadratic residues was first proven rigorously by Gauss, and is known as the Quadratic Reciprocity Law. It states:
Theorem (Quadratic Reciprocity Law): Let P and Q be odd prime numbers. Then
(P/Q)*(Q/P) = (-1)[(P-1)/2][(Q-1)/2] .
How do you compute a square root mod P?
We now have a computational method for determining for an odd prime number P whether a given a in NP is a quadratic residue mod P, or not. Once it is known that such a square root exists, one can proceed to try and find such a square root. How is this done?
A second, equally important question, is: suppose we know that a is a quadratic residue modulo the prime number P: Can we find a quadratic residue b modulo P such that b2 = a mod P? And what about the case when P is a composite number?
In the case when P = 3 mod 4, or where the modulus is a product of two distinct prime numbers, each equal to 3 mod 4, there is a simple algorithm for this:
First, one solves the quadratic equation x2 = a mod P for the case when P is an odd prime equal to 3 mod 4 and a is a quadratic residue mod P. The method is given in the following theorem.
Theorem: Let P be a prime number such that P mod 4 = 3. Let a be a quadratic residue mod P. Define k by (P-1)/2 = 2*k + 1. Then
x = ak+1 mod P
is a solution for x2 = a mod P. Moreover, x is a quadratic residue mod P, and is the only such solution to this equation.
Then, using the method for doing this, one solves the equation x2 mod R = a where R = P*Q and P and Q are two prime numbers, each equal to 3 mod 4. This is done by first solving each of the equations x2 = a mod P and x2 mod Q = a, and then using the Chinese remainder theorem to find the final result.
Thus, say we have found p in NP and q in NQ such that
p2 mod P = a and
q2 mod Q = a.
Then we use the technique of the Chinese Remainder Theorem to compute from p and q an element x of NR such that
x2 mod R = a.
(Tonelli-Shanks algorithm)