Navigation
Topics Register • News • History • How to • Sequences statistics • Template prototypes

P+1 factorization method

提供: Prime-Wiki
移動先: 案内検索

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: U0=0,U1=1,V0=2,V1=u Un=uUn1Un2,Vn=uVn1Vn2 for n2 where we can choose freely the integer u.

If we define D=u24, then for any odd prime p, p divides both gcd(N, UM) and gcd(N, VM2) whenever M is a multiple of p(D/p) where (D/p) is the Legendre symbol, which is equal to 1 if D is a quadratic residue mod p and -1 otherwise (we suppose that D is not multiple of p).

Since we do not know in advance the value of the Legendre symbol (because in order to compute it we need the prime factor p of N which is not known), it is possible that (D/p)=1 making this method a slow variant of p-1. So when the gcd does not reveal the prime factor of N we retry with a different value of u at least three times in order to have a high probability of selecting (D/p)=1.

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: V2n=Vn22 (duplication formula) Vm+n=VmVnVmn (addition formula)

In order to perform index multiplication by a natural number M, there are two approaches using the formulas shown above.

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 M in binary form. Then erase the first "1" (all numbers when represented in binary start with the digit "1"). Then for every "1" write the string "DA" and for every "0" write "D".

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 V21n using the recipe above we will get the sequence: V2n, V4n, V5n, V10n, V20n, V21n.

A problem with this approach is that the formula for addition shown above for Vq+r needs the value of Vqr. This can be overcomed by using another variable. When we compute Vkn we will be also computing V(k+1)n.

Then if we start with the pair (Vkn, V(k+1)n), when the bit equals zero we compute (V2kn, V(2k+1)n) and when the bit equals one we compute (V(2k+1)n, V2(k+1)n). In both cases we need one duplication and one addition requiring only two modular multiplications.

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 q between the bounds B1 and B2 and all the other prime factors less than B1.

Using the formula Vn=uVn1Vn2 we find that exchanging Vn and Vn+2 and adding two to n we get: Vn=uVn+1Vn+2. From this we get: V1=u=V1 and then Vn=Vn.

Let Vr be the number computed at the end of step 1. Now let C be the maximum multiple of 6 less than or equal to B1. The idea is to compute VCr and V6r. Then using the addition formula we can compute V(C+6)r,V(C+12)r,V(C+18)r,...,VB2r.

If q=C+1+6k the number computed will be equal to Vr and if q=C1+6k the number computed will be equal to Vr. Since Vr=Vr, we just multiply all V(C+6k)rVr(modN) and then take the GCD of the product in order to reveal the factor.

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: 62234
  • Duplicate index: 34221154
  • Duplicate index: 115422427936
  • Multiply index by 3: 42793622299066, so the first pair is (Vn,V2n)(427936,299066). The second pair is (V3n,V4n)(VnV2nVn,V2n22)(292372,342029)
  • Multiply index by 3: 29237222255586, so the first pair is (Vn,V2n)(292372,255586). The second pair is (V3n,V4n)(VnV2nVn,V2n22)(176913,33332)
  • Multiply index by 5: 17691322377427, so the first pair is (Vn,V2n)(176913,377427). The second pair is (V2n,V3n)(Vn22,VnV2nVn)(377427,447298). The third pair is (V5n,V6n)(V2nV3nVn,V3n22)(50045,290385).
  • Multiply index by 7: 5004522133185, so the first pair is (Vn,V2n)(50045,133185). The second pair is (V3n,V4n)(VnV2nVn,V2n22)(282419,245306). The third pair is (V7n,V8n)(V3nV4nVn,V4n22)(374468,138727).

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 Vr252303.

Initializing:

C=18
V18r392380
V24r224225
V6r446313

Computing all other V6kr:

V30r=V24rV6rV18r157772
V36r=V30rV6rV24r318875
V42r=V36rV6rV30r430332
V48r=V42rV6rV36r132372
(V18rVr)(V24rVr)...(V48rVr)421170
gcd(421170,451889)=139

External links