Shanks' square forms factorization

From Wikipedia, the free encyclopedia

Shanks' square forms factorization is a method for integer factorization, which was devised as an improvement on Fermat's factorization method.

The success of Fermat's method depends on finding integers x, and y such that x2y2 = N, where N is the integer to be factored, and a possible improvement (noticed by Kraitchik), is to look for integers x and y such that x^2\equiv y^2 \pmod{N}. Finding a pair (x,y) does not guarantee a factorisation of N, but it implies that N is a factor of x2y2 = (x-y)(x+y), and there is a good chance that the prime divisors of N are distributed between these two factors, so that calculation of the highest common factor of N and x-y will give a non-trivial factor of N.

A practical algorithm for finding pairs (x,y) which satisfy x^2\equiv y^2 \pmod{N} was developed by Shanks and was named "Square Forms Factorisation" or "SQUFOF". The algorithm can be couched either in terms of continued fractions or in terms of quadratic forms, and although there are now much more efficient factorisation methods available, SQUFOF has the advantage that it is small enough to be implemented on a programmable calculator.

[edit] Algorithm

Input: N, the integer to be factored, which must be neither a prime number nor a perfect square.

Output: a non-trivial factor of N.

The algorithm:

Initialize P_0=\lfloor\sqrt{N}\rfloor,Q_0=1,Q_1=N-P_0^2

Repeat

b_i=\left\lfloor\frac{\lfloor\sqrt{N}\rfloor+P_{i-1}}{Q_i}\right\rfloor,P_i=b_iQ_i-P_{i-1},Q_{i+1}=Q_{i-1}+b_i(P_{i-1}-P_i)

until Qi is a perfect square.

Initialize b_0=\left\lfloor\frac{\lfloor\sqrt{N}\rfloor-P_i}{\sqrt{Q_i}}\right\rfloor,P_0=b_0\sqrt{Q_i}+P_i,Q_0=\sqrt{Q_i},Q_1=\frac{N-P_0^2}{Q_0}

Repeat

b_i=\left\lfloor\frac{\lfloor\sqrt{N}\rfloor+P_{i-1}}{Q_i}\right\rfloor,P_i=b_iQ_i-P_{i-1},Q_{i+1}=Q_{i-1}+b_i(P_{i-1}-P_i)

until Pi + 1 = Pi.

Then gcd(N,Pi) is a non-trivial factor of N.

Example:

N=11111

P0=105 Q0=1 Q1=86

P1=67 Q1=86 Q2=77

P2=87 Q2=77 Q3=46

P3=97 Q3=46 Q4=37

P4=88 Q4=37 Q5=91

P5=94 Q5=91 Q6=25

Here Q6 is a perfect square

P0=104 Q0=5 Q1=59

P1=73 Q1=59 Q2=98

P2=25 Q2=98 Q3=107

P3=82 Q3=107 Q4=41

P4=82

Here P3=P4

gcd(11111, 82) = 41, which is a factor of 11111.

[edit] References

[edit] External link