Shanks' square forms factorization is a method for integer factorization devised by Daniel Shanks as an improvement on Fermat's factorization method. The success of Fermat's method depends on finding integers x and y such that x2−y2=N, where N is the integer to be factored. An improvement (noticed by Kraitchik) is to look for integers x and y such that x2≡y2(modN). Finding a suitable pair (x,y) does not guarantee a factorization of N, but it implies that N is a factor of x2−y2=(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 greatest common divisor of N and x−y will give a non-trivial factor of N. A practical algorithm for finding pairs (x,y) which satisfy x2≡y2(modN) was developed by Shanks, who named it Square Forms Factorization or SQUFOF. The algorithm can be expressed in terms of continued fractions or in terms of quadratic forms. Although there are now much more efficient factorization methods available, SQUFOF has the advantage that it is small enough to be implemented on a programmable calculator. Shanks programmed it on an HP-65, made in 1974, which has storage for only nine digit numbers and allows only 100 steps/keystrokes of programming. There are versions of the algorithm that use little memory and versions that store a list of values that run more quickly. In 1858, the Czech mathematician Václav Šimerka used a method similar to SQUFOF to factor (1017−1)/9 = 11111111111111111 = 2071723⋅5363222357.
Algorithm Note This version of the algorithm works on some examples but often gets stuck in a loop. This version does not use a list. Input: N, the integer to be factored, which must be neither a prime number nor a perfect square, and a small positive integer, k. Output: a non-trivial factor of N. The algorithm:
Shanks' method has time complexity O(N4). Stephen S. McMath wrote a more detailed discussion of the mathematics of Shanks' method, together with a proof of its correctness.
Example Let N=11111 Q−1=1
Here Q5=25 is a perfect square, so the first phase ends. For the second phase, set Q−1=25=5. Then:
Here P3=P4=82, so the second phase ends. Now calculate gcd(11111,82)=41, which is a factor of 11111. Thus, N=11111=41⋅271.
Example implementation Below is an example of C function for performing SQUFOF factorization on unsigned integer not larger than 64 bits, without overflow of the transient operations.
References
D. A. Buell (1989). Binary Quadratic Forms. Springer-Verlag. ISBN 0-387-97037-1. D. M. Bressoud (1989). Factorisation and Primality Testing. Springer-Verlag. ISBN 0-387-97040-1. Riesel, Hans (1994). Prime Numbers and Computer Methods for Factorization (2nd ed.). Birkhauser. ISBN 0-8176-3743-5. Gower, Jason E. (December 2004). Square form factorization (PDF) (PhD thesis). Purdue University. CERIAS Tech Report 2004-31. A very detailed analysis of SQUFOF Gower, Jason E.; Wagstaff, Samuel S. Jr. (January 2008). "Square Form Factorization" (PDF). Mathematics of Computation. 77 (261): 551–588. Bibcode:2008MaCom..77..551G. doi:10.1090/S0025-5718-07-02010-8. A summary of the preceding thesis, also very detailed. Samuel S. Wagstaff, Jr. (2013). The Joy of Factoring. Providence, RI: American Mathematical Society. pp. 163–168. ISBN 978-1-4704-1048-3.
External links Daniel Shanks: Analysis and Improvement of the Continued Fraction Method of Factorization, (transcribed by S. McMath 2004) Daniel Shanks: SQUFOF Notes, (transcribed by S. McMath 2004) Stephen S. McMath: Parallel integer factorization using quadratic forms, 2005 S. McMath, F. Crabbe, D. Joyner: Continued fractions and parallel SQUFOF, 2005 Jason Gower, Samuel Wagstaff: Square Form Factorisation (Published) Shanks's SQUFOF Factoring Algorithm java-math-library