In our last lesson, we focused on the computational engine of public-key cryptography: the square-and-multiply algorithm for modular exponentiation. We analyzed its efficiency, which is what makes systems like RSA practical. Today, we shift our focus to another fundamental question in number theory with deep cryptographic implications: how to determine if a number has a square root modulo another number.
This question, known as determining quadratic residuosity, is central to several cryptographic protocols, including the Goldwasser-Micali cryptosystem and some zero-knowledge proofs. Our goal in this lesson is to master the tools for answering this question efficiently: the Legendre and Jacobi symbols. We will define these symbols, understand their properties, and, most importantly, develop an efficient algorithm for their computation that leverages your computer science background.
Quadratic Residues and the Legendre Symbol
The core problem is to determine whether the congruence has a solution, where is an odd prime.
- If a solution exists and , we say that is a quadratic residue modulo .
- If no solution exists, we say is a quadratic non-residue modulo .
To formalize this, mathematicians introduced the Legendre symbol. The following video provides a concise definition and a clear example.
Number Theory | The Legendre Symbol and Euler's Criterion
This video by Michael Penn introduces the concept of quadratic residues and defines the Legendre symbol as a way to classify them.
Watch the first segment of the video, from the beginning until the example with p=7. This will give you the formal definition of the Legendre symbol, denoted (\frac{a}{p}), and its values (1, -1, or 0).
As the video explains, the Legendre symbol is defined as:
Euler's Criterion
A first, powerful method for calculating the Legendre symbol connects directly to our previous lesson on modular exponentiation. Euler's criterion states that for an odd prime and an integer such that :
This is a remarkable result. It transforms the problem of finding a square root into a modular exponentiation problem, which we know how to solve efficiently using the square-and-multiply algorithm.
[PDF] 1.1 Legendre Symbol - CSE IIT KGP
These lecture notes from IIT Kharagpur provide a formal statement of the key properties of the Legendre symbol.
Please read the definition and the list of properties in this document. Start at the definition of the Legendre symbol. Then, review the list of properties in Proposition 1, paying special attention to property 3, which is Euler's Criterion.
The proof of Euler's criterion is elegant and reinforces concepts like Fermat's Little Theorem. You can watch the proof in the same Michael Penn video from
A More Efficient Path: The Law of Quadratic Reciprocity
While Euler's criterion provides a computational path, a deeper structure discovered by Gauss provides an even more efficient method, especially for calculations by hand or for building recursive algorithms. This structure is captured by the Law of Quadratic Reciprocity.
This law and its supplements allow us to "flip" and reduce Legendre symbols in a way that is reminiscent of the Euclidean algorithm for finding the greatest common divisor.
The main results are:
-
Law of Quadratic Reciprocity: For distinct odd primes and :
This means unless both and are of the form , in which case . -
First Supplement:
-
Second Supplement:
Using these rules, along with the multiplicative property , we can break down any Legendre symbol into smaller, easily computable pieces. For example, to compute :
- and are both prime. Since , we can flip the symbol without a sign change: .
- Reduce the numerator modulo the denominator: , so we have .
- Use multiplicativity: .
- Apply the second supplement: Since , .
- Therefore, , and 29 is a quadratic non-residue modulo 53.
Notice a potential bottleneck: in the step , we had to find the prime factorization of 24. For large numbers, this factorization step is computationally very expensive. This is the motivation for our next tool.
The Jacobi Symbol: A Computational Generalization
The Jacobi symbol, also denoted , generalizes the Legendre symbol to odd composite denominators . Its primary purpose is not to test for quadratic residuosity directly, but to serve as an efficient computational tool.
Introduction to number theory lecture 35 Jacobi symbol
This lecture provides a clear and rigorous introduction to the Jacobi symbol, highlighting its computational advantages and a crucial point of difference from the Legendre symbol.
First, watch the introduction from the definition to see how the Jacobi symbol is defined based on the prime factorization of the denominator. Next, from the properties, note that all the key properties of the Legendre symbol, including the Law of Quadratic Reciprocity, carry over. Then, watch the critical segment from the big warning. This explains the most important difference between the two symbols. Finally, see from the computational advantage how the Jacobi symbol allows for a fast, Euclid-like algorithm.
Let's summarize the key points from the video.
Definition: If is the prime factorization of an odd integer , the Jacobi symbol is defined as:
where the symbols on the right are Legendre symbols.
The Crucial Warning:
As emphasized in the video, if is composite, does not imply that is a quadratic residue modulo . For example, . However, has no solution because it would require solutions modulo 3 and 5, and has no solution.
However, if , we can definitively conclude that is a quadratic non-residue modulo .
The Computational Advantage:
The power of the Jacobi symbol is that all the reciprocity laws hold. This means we can use the "flip and reduce" strategy without ever needing to factor the numerator. This leads to an algorithm with a complexity similar to the Euclidean algorithm.
The following document provides a side-by-side comparison that makes this advantage crystal clear.
[PDF] NUMBER THEORY NOTES ON JACOBI SYMBOLS Vanderbilt ...
This document from Vanderbilt University demonstrates the power of the Jacobi symbol with a concrete example.
Read the section titled Example near the end of the document. It computes (\frac{713}{1009}) using two methods: Method 1 (Legendre) and Method 2 (Jacobi). Notice how Method 1 requires factoring 713 = 23 \cdot 31, while Method 2 proceeds directly by flipping (\frac{1009}{713}) without needing to know the factors of 713.
An Efficient Algorithm for the Jacobi Symbol
We can now formalize the process into an algorithm. This algorithm computes efficiently by repeatedly reducing the numerator, factoring out powers of 2, and applying the reciprocity law to flip the numerator and denominator.
[PDF] 1.1 Legendre Symbol - CSE IIT KGP
These notes formalize the computational process into a concrete algorithm and analyze its efficiency.
Please read the entire section 1.4 Computation of Jacobi Symbol. It begins with a list of rules for the computation. Then, study the pseudocode for the jacobi(a, n) function. Finally, read the complexity analysis which shows that the number of iterations is O(\log n), just like the Euclidean algorithm.
The jacobi(a, n) algorithm presented is a beautiful piece of computational number theory. It elegantly combines modular arithmetic and the reciprocity laws into a tight, efficient loop that avoids the hard problem of integer factorization. Understanding this algorithm is the main goal of this lesson.
Conclusion
In this lesson, we have built the machinery to efficiently determine quadratic residuosity.
Key Takeaways:
- Quadratic Residues: An integer is a quadratic residue modulo if has a solution.
- Legendre Symbol : A function that is +1 for quadratic residues, -1 for non-residues, and 0 for multiples of . It is defined only for prime denominators.
- Euler's Criterion: Connects the Legendre symbol to modular exponentiation: .
- Law of Quadratic Reciprocity: A set of rules that allow for the efficient, recursive computation of the Legendre symbol.
- Jacobi Symbol : A generalization to odd composite denominators . Its main purpose is computational efficiency.
- Critical Distinction: does not imply is a quadratic residue modulo . However, does imply is a non-residue.
- Efficient Algorithm: By using the reciprocity laws for the Jacobi symbol, we can compute it in logarithmic time without factoring the numerator, much like the Euclidean algorithm for GCD.
We have seen how the Law of Quadratic Reciprocity enables this efficient computation, but we have taken the law itself as given. In our next lesson, we will delve into the "why". We will formally state and then prove this cornerstone theorem of number theory, exploring one of its most elegant proofs.