FatoriazationExamples.mws

Factorization problems and examples

İMike May, S.J. 2002, maymk@slu.edu

>    restart:

As we have been looking at RSA, it is worthwhile to look at products of primes, p and q, such that n=p*q is easily factorable by special techniques.  (We want to identify weaknesses in the algorithm to avoid them in implementation.)  Some of the exercises from chapter 6 illoustrate the methods.

The p-1 method

The first method to look at is the p-1 method.  This method works when p-1 or q-1 factors as a product of small primes.  (For this worksheet, small primes ar less than 100.)  Without loss of generality assume p-1 factors as a product of small primes.  More specifically assume that p-1 divides 100!.  Then 2^(100!) mod n is congruent to 1 mod p, and p divides 2^(100!) - 1 mod n. Taking the gcd of that number and n should produce p.

Example 1

Computer Exercise 4 asks you to factor 618240007109027021 by the p-1 method.  We compute 2^(100!) mod n.  

(Be sure to use

Power (2,100!) mod n

rather than
2^(100!) mod n.

The second tries to compute the power before reducing and will run out of memory.  The first reduces mod n at each step.)

>    n := 618240007109027021;
b1 := 100!;
t1 := Power(2, b1) mod n;

n := 618240007109027021

b1 := 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
b1 := 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

t1 := 78737314835659020

Next we find a factor of n.  We test if it is prime and see how p-1 factors.

>    factor1 := igcd(t1-1,n);
isprime(factor1);
ifactor(factor1-1);

factor1 := 250387201

true

``(2)^8*``(3)^5*``(5)^2*``(7)*``(23)

Finding the other factor is a matter of division.  Once again we check if it is priime and find the factors of q-1.

>    factor2 := n/factor1;
isprime(factor2);
ifactor(factor2-1);

factor2 := 2469135821

true

``(2)^2*``(5)*``(123456791)

Thus 618240007109027021 = (250387201)(2469135821);

Example 2

Computer Exercise 5 asks you to factor 8834884587090814646372459890377418962766907.  We repeat the process form above.

>    n1:=8834884587090814646372459890377418962766907:

>    b1 := 100!:
t1 := Power(2, b1) mod n1;
factor1 := igcd(t1-1, n1);

t1 := 961623821657800055077023229270715484248143

factor1 := 364438989216827965440001

>    factor2 := n1/factor1;

factor2 := 24242424242468686907

It is worth noting that this fatcorization gives difficulties to the ifactor command which is not looking for such special cases.  When we try using the command we give up and interupt the computation after a while.

>    ifactor(n1);

``(24242424242468686907)*``(364438989216827965440001)

>   

Computer Exercise 6:
85975324443166^2 = 462436106261^2 mod 537069139875071.

>    factor1 := igcd(85975324443166-462436106261,537069139875071);

factor1 := 9876469

>    factor2 := 537069139875071/factor1;

factor2 := 54378659

Exercise 9

>    n := 642401;
factor1 := igcd(516107*187722-2*7, n);

n := 642401

factor1 := 1129

>    factor2 := n/factor1;

factor2 := 569

>