Contents
Shanks's square forms factorization
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 x^2-y^2=N, where N is the integer to be factored. An improvement (noticed by Kraitchik) is to look for integers x and y such that. Finding a suitable pair (x, y) does not guarantee a factorization of N, but it implies that N is a factor of, 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 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 = =.
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: Initialize Repeat until Q_i is a perfect square at some odd value of i. Start the second phase (reverse cycle). Initialize, , and , where P_0, P_i, and Q_{i} are from the previous phase. The b_0 used in the calculation of P_0 is the recently calculated value of b_0. Set i=0 and, where P_0 is the recently calculated value of P_0. Repeat until Then if is not equal to 1 and not equal to N, then f is a non-trivial factor of N. Otherwise try another value of k. Shanks' method has time complexity. 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 Q_{5} = 25 is a perfect square, so the first phase ends. For the second phase, set. Then: Here, so the second phase ends. Now calculate, which is a factor of 11111. Thus,.
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.
This article is derived from Wikipedia and licensed under CC BY-SA 4.0. View the original article.
Wikipedia® is a registered trademark of the
Wikimedia Foundation, Inc.
Bliptext is not
affiliated with or endorsed by Wikipedia or the
Wikimedia Foundation.