In number theory, a congruence of squares is a congruence commonly used in integer factorization algorithms.
Given a positive integer n, Fermat's factorization method relies on finding numbers x and y satisfying the equality
x2-y2=n
We can then factor n = x2 − y2 = (x + y)(x − y). This algorithm is slow in practice because we need to search many such numbers, and only a few satisfy the equation. However, n may also be factored if we can satisfy the weaker congruence of squares conditions:
x2\equivy2\pmod{n}
x\not\equiv\pmy\pmod{n}
From here we easily deduce
x2-y2\equiv0\pmod{n}
(x+y)(x-y)\equiv0\pmod{n}
This means that n divides the product (x + y)(x − y). The second non-triviality condition guarantees that n does not divide (x + y) nor (x − y) individually. Thus (x + y) and (x − y) each contain some, but not all, factors of n, and the greatest common divisors of (x + y, n) and of (x − y, n) will give us these factors. This can be done quickly using the Euclidean algorithm.
Most algorithms for finding congruences of squares do not actually guarantee non-triviality; they only make it likely. There is a chance that a congruence found will be trivial, in which case we need to continue searching for another x and y.
Congruences of squares are extremely useful in integer factorization algorithms. Conversely, because finding square roots modulo a composite number turns out to be probabilistic polynomial-time equivalent to factoring that number, any integer factorization algorithm can be used efficiently to identify a congruence of squares.
A technique pioneered by Dixon's factorization method and improved by continued fraction factorization, the quadratic sieve, and the general number field sieve, is to construct a congruence of squares using a factor base.
Instead of looking for one pair
stylex2\equivy2\pmodn
stylex2\equivy\pmodn
The set of small primes which all the y factor into is called the factor base. Construct a logical matrix where each row describes one y, each column corresponds to one prime in the factor base, and the entry is the parity (even or odd) of the number of times that factor occurs in y. Our goal is to select a subset of rows whose sum is the all-zero row. This corresponds to a set of y values whose product is a square number, i.e. one whose factorization has only even exponents. The products of x and y values together form a congruence of squares.
This is a classic system of linear equations problem, and can be efficiently solved using Gaussian elimination as soon as the number of rows exceeds the number of columns. Some additional rows are often included to ensure that several solutions exist in the nullspace of our matrix, in case the first solution produces a trivial congruence.
A great advantage of this technique is that the search for relations is embarrassingly parallel; a large number of computers can be set to work searching different ranges of x values and trying to factor the resultant ys. Only the found relations need to be reported to a central computer, and there is no particular hurry to do so. The searching computers do not even have to be trusted; a reported relation can be verified with minimal effort.
There are numerous elaborations on this technique. For example, in addition to relations where y factors completely in the factor base, the "large prime" variant also collects "partial relations" where y factors completely except for one larger factor. A second partial relation with the same larger factor can be multiplied by the first to produce a "complete relation".
We take n = 35 and find that
style62=36\equiv1=12\pmod{35}
We thus factor as
\gcd(6-1,35) ⋅ \gcd(6+1,35)=5 ⋅ 7=35
Using n = 1649, as an example of finding a congruence of squares built up from the products of non-squares (see Dixon's factorization method), first we obtain several congruences
412\equiv32=25\pmod{1649},
422\equiv115=5 ⋅ 23\pmod{1649},
432\equiv200=23 ⋅ 52\pmod{1649}.
Of these, the first and third have only small primes as factors, and a product of these has an even power of each small prime, and is therefore a square
32 ⋅ 200=25+3 ⋅ 52=28 ⋅ 52=(24 ⋅ 5)2=802
yielding the congruence of squares
32 ⋅ 200=802\equiv412 ⋅ 432\equiv1142\pmod{1649}.
So using the values of 80 and 114 as our x and y gives factors
\gcd(114-80,1649) ⋅ \gcd(114+80,1649)=17 ⋅ 97=1649.
. David Bressoud . Factorization and Primality Testing . 8. The Quadratic Sieve . 1989 . 0-387-97040-1 . Undergraduate Texts in Mathematics . Springer-Verlag .
. Samuel S. Wagstaff Jr. . The Joy of Factoring . . Student mathematical library . 68 . Providence, RI . 2013 . 1-4704-1048-6 . 195–202.