2.4.4 Quadratic Sieve Factoring


The idea behind quadratic factoring is the following:
Let be x, y ∈ Z, such that x2 ≡ y2 (mod n), but x ≠ y (mod n). Then n divides x2 - y2 = (x - y) ⋅(x + y) but n does not divide neither (x - y) nor (x + y). Hence gcd(x - y, n) must be a non-trivial factor of n. A common strategy for finding such x and y is the following:
Let be S = {p1, p2, ..., pt } the set of the first t primes (= factor base). Find pairs (ai , bi ) such that:
(i) ai2 ≡ bi (mod n) and
(ii) bi = ∏tj=1 pje ij , eij ≥ 0, so bi is pt - smooth.

Now find a subset of bi's such that its product is a perfect square. That means all the eij's have to be even. For simplifying, identify the binary vector vi = (vi1 , vi2 , ..., vit ) with the exponent vector (ei1 , ei2 , ..., eit ), such that v ij = eij mod 2. If t + 1 pairs (ai ,bi ) occur, the t - dimensional vectors v1 ,v 2 , ..., vt+1 are linear dependant over Z2. Hence there is a subset T ⊆ {1, 2, ..., t + 1} such that ∑ i ∈ T vi = 0 over Z2 and so ∏ i ∈ T bi is a perfect square. It is obvious that ∏i ∈ T ai2 is a perfect square, too. Thus setting x = ∏ i ∈ T ai and y as a square root of ∏ i ∈ T bi yields a pair (x, y) such that x2 ≡ y2 (mod n). If this pair satisfies x ≠ y (mod n), then gcd(x - y, n) yields a non-trivial factor of n. Otherwise you can replace some of the pairs (ai , bi ) by new pairs.

Definition: (Legendre- symbol)
The Legendre- symbol (a/b) for a, b ∈ Z is defined as follows:
(a/b) = 0, if p | a,
(a/b) = 1, if a is a quadratic residuo modulo p
(a/b) = -1, if a is a non-quadratic residuo modulo p.

Quadratic Sieve Factoring uses now an efficient method for finding such pairs (ai , bi ):
Let be m = ⌊ √n ⌋ , and consider q(x) = x2 + 2mx + m2 - n ≈ x2 + 2mx which is small (with respect to n), if x is small. The sieve algorithm chooses ai = (x + m) and checks whether bi = (x + m)2 - n is pt - smooth. Note that: ai2 = (x + m)2 ≡ bi (mod n). Note also that if a prime p divides bi it follows that (x + m)2 ≡ n (mod p) and so n is a quadratic residuo modulo p. Consequently the factor base only needs to contain such primes p for which the Legendre-symbol (n/p) = 1. Further on the factor base should include "-1" because of the negative bi's.

Example:
1. Choose a factor base with t = 6 to find non-trivial factors of n = 24961.
Consequently S = {-1, 2, 3, 5, 13, 23} (For 7, 11, 17, 19 is (n/p) = -1)
2. Now compute m = ⌊ √24961 ⌋ = 157.
3. After that you compute 7 ai's and bi's with different x's in q(x) = (x + m)2 - n, so that q(x) is 23-smooth.
That leads to the following:
x1 = 0, q(x1 )= -312 = -23⋅3⋅13, a1 = 157, v1 = (1, 1, 1, 0, 1, 0)
x2 = 1, q(x2 )= 3, a2 = 158, v2 = (0, 0, 1, 0, 0, 0)
x3 = -1, q(x3 )= -625 = -54, a3 = 156, v3 = (1, 0, 0, 0, 0, 0)
x4 = 2, q(x4 )= 320 = 26⋅5, a4 = 159, v4 = (0, 0, 0, 1, 0, 0)
x5 = -2, q(x5 )= -936 = -23⋅32 ⋅13, a5 = 155, v1 = (1, 1, 0, 0, 1, 0)
x6 = 4, q(x6 )= 960 = 26⋅3⋅5, a6 = 161, v6 = (0, 0, 1, 1, 0, 0)
x7 = -6, q(x7 )= -2160 = -24⋅33 ⋅5, a7 = 151, v7 = (1, 0, 1, 1, 0, 0)
4. E.g. for T = {1, 2, 5} is v1 + v2 + v5 = 0
5. x = (a1 ⋅a2 ⋅a5 mod n) = 936
6. l1 = 1, l2 = 3, l3 = 2, l4 = 0, l5 = 1, l6 = 0
7. y = -23 ⋅ 32 ⋅ 13 mod n = 24025

8. Because of 936 ≡ -24025 (mod n), there must be found another T

9 Now for T = {3, 6, 7} is v3 + v6 + v7 = 0
10. x = (a3 ⋅a6 ⋅a7 mod n) = 23045
11. l1 = 1, l2 = 5, l3 = 2, l4 = 3 , l5 = 0, l6 = 0
12. y = -25 ⋅ 32 ⋅ 53 mod n = 13922 13. Now 23405 ≠ 13922 (mod n), so that ggT(x - y, n) = ggT(9483, 24961) = 109.
That means we found two non-trivial factors of 24961 109 and 229.

Applet quadratic Sieve Factoring

Source code:
QuadAlgSF.java - Applet Surface
QuadAlg.java - Algorithm Class
Matrix.java - Matrix Class

2.5.1 Shank's algorithm