Topics | Register • News • History • How to • Sequences statistics • Template prototypes |
P+1 factorization method
The p+1 factorization method of factoring integers was discovered by Hugh Williams in 1982 and it is based in the p-1 method.
Instead of using multiplications modulo p, this method uses Lucas sequences. They have very interesting properties that make them useful in the Lucas-Lehmer test.
Let's define the following Lucas sequence:
If we define
Since we do not know in advance the value of the Legendre symbol (because in order to compute it we need the prime factor
From the formulas above, the values Un are not needed to compute the value of Vn, so they are not used in this algorithm.
Step 1
The step 1 works in the same way as explained in the P-1 factorization method except that instead of computing an (mod N) we compute Vn (mod N) and instead of computing gcd(an - 1, N) we compute gcd(Vn - 2, N).
The main computation in step 1 is to find Vmn from Vn (index multiplication). In order to compute the Lucas sequence for high values of the index, the formulas given at the beginning of this article are not useful. Instead, we will use the two formulas shown below:
In order to perform index multiplication by a natural number
Montgomery's PRAC is an almost optimal algorithm, but this is too complicated to explain it here.
Another algorithm is the same used in exponentiation. We represent the value
For example for the number 21 which is 10101 when written in binary, you will have the string DDADDA. The letter D means duplication and A means addition.
So if we have to compute
A problem with this approach is that the formula for addition shown above for
Then if we start with the pair (
The index multiplication explained above can be translated to pseudocode as follows (let B = Vn):
x=B y=(B^2-2) mod N for each bit of M to the right of the most significant bit if the bit is 1 x=(x*y-B) mod N y=(y^2-2) mod N else y=(x*y-B) mod N x=(x^2-2) mod N V=x
The PRAC algorithm is 30% faster in average than the algorithm shown above to multiply a point by a natural number.
Step 2
The step 2 is useful when p+1 has a prime factor
Using the formula
Let
If
Example
Let's factor N = 451889 with u = 6 and B1 = 10. All congruences below will be modulo N.
As in the example of the P-1 factorization method we get:
E = 23 × 32 × 5 × 7
V1 = u = 6.
- Duplicate index:
- Duplicate index:
- Duplicate index:
- Multiply index by 3:
, so the first pair is . The second pair is - Multiply index by 3:
, so the first pair is . The second pair is - Multiply index by 5:
, so the first pair is . The second pair is . The third pair is . - Multiply index by 7:
, so the first pair is . The second pair is . The third pair is .
So gcd(374468 - 2, 451889) = 139 which is a proper factor of the original number.
Notice that some values computed above are not really useful if you had to perform the computation by hand, for example the second element of the pair in the last step of the index multiplication. When using a computer, these additional multiplication can be avoided by using conditional sentences.
If instead of u=6 we would have selected u=7, the final gcd would have been: gcd(252303-2, 451889) = 1, so this particular value u=7 is not useful in the p+1 method.
Since u=7 does not factor 451889 in step 1, we have to continue with step 2. Let the upper bound B2 be 50. From the previous paragraph
Initializing:
Computing all other