GO-V.ORG
As seen in

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 x^2\equiv y^2\pmod{N . Finding a suitable pair (x, y) does not guarantee a factorization of N , but it implies that N is a factor of x^2-y^2=(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... Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.

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 x^2\equiv y^2\pmod{N} . Finding a suitable pair (x, y) does not guarantee a factorization of N , but it implies that N is a factor of x^2-y^2=(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 x^2\equiv y^2\pmod{N} 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 (10^{17} - 1)/9 = 11111111111111111 = 2071723 \cdot 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: {{olist |1=(Phase 1, forward cycle.) Initialize \begin{align} i&=0,\\ P_0&=\lfloor\sqrt{kN}\rfloor,\\ Q_{-1}&=1,\\ Q_0&=kN-P_0^2. \end{align} |2=Repeat \begin{align} i&=i+1,\\ b_i&=\left\lfloor\frac{P_0+P_{i-1}}{Q_{i-1}}\right\rfloor,\\ P_i&=b_iQ_{i-1}-P_{i-1},\\ Q_i&=Q_{i-2}+b_i(P_{i-1}-P_i) \end{align} until Q_i is a perfect square at some odd value of i . |3=(Phase 2, reverse cycle.) Initialize \begin{align} j&=0,\\ S_{-1}&=\sqrt{Q_i},\\ b_0&=\left\lfloor\frac{P_0-P_i}{\sqrt{Q_i}}\right\rfloor,\\ R_0&=b_0\sqrt{Q_i}+P_i,\\ S_0&=\frac{kN-R_0^2}{T_{-1}} \end{align} where P_0, P_i , and Q_{i} are from the previous phase. (The variables j, R, S correspond to the i, P, Q from the first loop.) |4=Repeat \begin{align} j&=j+1,\\ b_j&=\left\lfloor\frac{R_0+R_{j-1}}{S_{j-1}}\right\rfloor,\\ R_j&=b_iS_{j-1}-R_{j-1},\\ S_j&=S_{j-2}+b_j(R_{j-1}-R_j) \end{align} until R_j=R_{j-1}. Then if f=\gcd(N,R_j) 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 O(\sqrt[4]{N}) . 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 Q_{-1} = \sqrt{25} = 5 . Then: Here P_{3} = P_{4} = 82 , so the second phase ends. Now calculate gcd(11111, 82) = 41 , which is a factor of 11111 . Thus, N = 11111 = 41 \cdot 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. include define nelems(x) (sizeof(x) / sizeof((x)[0])) const int multiplier[] = {1, 3, 5, 7, 11, 3*5, 3*7, 3*11, 5*7, 5*11, 7*11, 3*5*7, 3*5*11, 3*7*11, 5*7*11, 3*5*7*11}; uint64_t SQUFOF( uint64_t N ) { uint64_t D, Po, P, Pprev, Q, Qprev, q, b, r, s; uint32_t L, B, i; s = (uint64_t)(sqrtl(N)+0.5); if (s*s == N) return s; for (int k = 0; k = B) continue; b = (uint64_t)((Po - P)/r); Pprev = P = b*r + P; Qprev = r; Q = (D - Pprev*Pprev)/Qprev; i = 0; do { b = (uint64_t)((Po + P)/Q); Pprev = P; P = b*Q - P; q = Q; Q = Qprev + b*(Pprev - P); Qprev = q; i++; } while (P != Pprev); r = gcd(N, Qprev); if (r != 1 && r != N) return r; } return 0; } ==References== A very detailed analysis of SQUFOF A summary of the preceding thesis, also very detailed.

source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Shanks's square forms factorization". 1775479569. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1347408943

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·