You are on page 1of 17

COMP 446

TERM PROJECT

Factoring Large Integers


Using Pollard-rho Algorithm

Najeeb Ahmad

Koç University, Istanbul, Turkey


Problem Definition

Given an integer with two prime factors,
find the prime factors
– The integer can be arbitrarily large
Motivation

Learn how an NP problem with no known
polynomial time algorithm can be practically
solved

Learn how to deal with arbitrarily large numbers
in computer programming
Requirements

Part I: To implement Pollard-rho algorithm for
factoring small integers

Part II: To implement Pollard-rho algorithm for
arbitrarily factoring large integers

Discuss algorithm iterations for factoring some
large integers

Input/Output:
– Input: Number to be factorized
– Output: Two prime factors
Factoring Algorithms

No polynomial time algorithm exists

Algorithms can broadly classified into
– Special purpose

Running time depends on smaller prime
factor
– General purpose

Running time depends on size of the integer

General Number Field Sieve (GNFS) has sub-
exponential time complexity
Pollard-rho Algorithm

Basically a heuristic
– Neither running time, nor success
guaranteed

Effective for huge integers with at least one
small prime factor
Pollard-rho Algorithm

Concepts Employed
– Birthday paradox: In a group of people,
probability of two people having same
birthday is unexpectedly high
– Floyd’s cycle algorithm: A hare and tortoise
moving in circle with hare twice as fast as
tortoise, will eventually meet up
Pollard-rho Algorithm
Pollard-rho(N)
Randomly select x = 2 to N-1
Set y = x
Randomly select c = 1 to N-1
while(d == 1)
a = (x2+c) mod N // Tortoise move
b= (y2+c) mod N
b=(b2+c)mod N // Hare move
d=GCD(|b-a|, N)
x=a
y=b
factor1=d
factor2=N/d
print factor1, factor2
Euclidean Algorithm for GCD
GCD(a, b)
if(b==0)
return a
GCD(b,a%b)
Implementation

Implementation in C++
– GNU g++ compiler
– Ubuntu OS

GNU GMP big number library
Time and Space Complexity

Time complexity
– For a given N, upto N1/4 iterations
– In terms of input length, O(2n/4)
– In terms of smaller factor, O(sqrt(smaller factor))

Space complexity
– O(1), fixed amount of memory required
Results

Inputs
Ser Integer Factor 1 Factor 2

1 5352499 1237 4327


2 670726081 12347 54323
3 9449868410449 1234577 7654337
4 1082154235955237 12345701 87654337
5 121932633334857493 123456791 987654323
6 13565005454706599869 1234567907 10987654367
7 1049178520185305599951 1049179854847 999998727899999
445153
8 6863443896321848516323 8284590452353 8284590452353
6609
9 6913224604942703086730 777737777777777 888888877777777
95061729
Results

Iterations
Ser Trial Division iterations Pollard Rho Max Min iterations saved
(t) iterations (p) (t-p)
1 1237 117 1120
2 12347 404 11943
3 1234577 3882 1230695
4 12345701 10651 12335050
5 123456791 37674 123419117
6 1234567907 121170 12344446737
7 104917985484847 3081552 1049176773295
8 8284590452353 4017582 8284586434771
9 777737777777777 57635844 777737720141933
Results

Iterations
Ser Pollard Rho Average Sqrt (smaller
iterations factor) Approx.
1 30 35
2 98 111
3 1035 1111
4 3368 3513
5 10181 11111
6 32910 35136
7 1048082 1024294
8 2420429 2878296
9 24681730 27887950
Results
Results

Test on Fermat’s 8th number
– 115792089237316195423570985008687907
853269984665640564039457584007913129
639937
– Factor 1=1238926361552897
– Factor 2 =
934616397153579777691635581996068965
84051237541638188580280321

Took 6 minutes, 10 seconds on Intel I7 @2.60
GHz with 8GB RAM

35370057 iterations, just over 35198385
Demo and Q&A

You might also like