Proof of Pollard's Rho Algorithm
Algorithm
Let’s say that an element of a group has order . Then, the discrete logarithm problem can be solved in no more than steps according to the following algorithm.
Step 1.
Compute and .
Step 2.
Find the solution to the discrete logarithm problem using Shanks’ algorithm.
Step 3.
Find that satisfies using the Chinese Remainder Theorem.
- is the time it takes for Shanks’ algorithm, which is about .
Shanks’ algorithm is an attack method that can be used when the order is known. The Pollard-Rho algorithm utilizes the fact that if is smooth, then the factorization of becomes easier, making it easier to find . The order of the created is trivially , removing the constraint of using Shanks’ algorithm. This involves reducing the original problem into smaller problems, solving them individually, and then obtaining the answer using the Chinese Remainder Theorem.
Proof
Part 1. Existence
That is a solution to means that for all , there exists that satisfies .
- Part 1-1.
By the definition of and , is obtained. To organize, and taking the logarithm gives - Part 1-2.
It is trivial that holds according to the definition of , and by the Extended Euclidean Theorem, there exists . - Part 1-3.
From Part 1-1, Multiplying both sides of by gives Adding this from to gives and are independent of index , so From Part 1-2, since , it follows
Part 2. Time Complexity
Since Step 2 is repeated for every , it takes . Moreover, because using the Chinese Remainder Theorem in Step 3 takes time ,
■
Code
The following is the implementation of the Pollard-Rho algorithm in R. Factorization code, Code for finding the order, Shanks’ algorithm, Exponentiation by squaring, and Code using the Chinese Remainder Theorem were used.
prime = read.table("../attachment
/cfile8.uf@25411C3C5968BBE322F0D4.txt"); prime = prime[,1]
factorize<-function(p)
{
q=p
factors<-numeric(0)
i=1; j=1
while(q!=1)
{
if(q%%prime[i]) {i=i+1}
else
{
q<-q/prime[i]
factors[j]<-prime[i]
i=1
j=j+1
}
}
return(factors)
}
order<-function(g,p,h=1) #Calculate a order of g in modulo p
{
qe<-table(factorize(p-1))
qe<-rbind(as.numeric(names(qe)),qe)
divisor<-qe[1,1]^(0:qe[2,1])
if((length(qe)/2)==1) {return(qe[1,1]^qe[2,1])}
for(i in 2:(length(qe)/2)) {divisor=c(divisor%*%t(qe[1,i]^(0:qe[2,i])))}
for(i in divisor) {if((FPM(g,i,p))%%p==1) break;}
return(i)
}
FPM<-function(base,power,mod) #It is equal to (base^power)%%mod
{
i<-0
if (power<0) {
while((base*i)%%mod != 1) {i=i+1}
base<-i
power<-(-power)}
if (power==0) {return(1)}
if (power==1) {return(base%%mod)}
n<-0
while(power>=2^n) {n=n+1}
A<-rep(1,n)
A[1]=base
for(i in 1:(n-1)) {A[i+1]=(A[i]^2)%%mod}
for(i in n:1) {
if(power>=2^(i-1)) {power=power-2^(i-1)}
else {A[i]=1} }
for(i in 2:n) {A[1]=(A[1]*A[i])%%mod}
return(A[1])
}
shanks<-function(g,h,p)
{
N<-order(g,p)
n<-1+floor(sqrt(N))
gn<-FPM(g,-n,p) #gn := g^{-n}
x<-p
List_1<-numeric(n+1)
List_1[1]=1
for(i in 1:n) {List_1[i+1]=(List_1[i]*g)%%p}
List_2<-numeric(n+1)
List_2[1]=h
for(i in 1:n) {List_2[i+1]=(List_2[i]*gn)%%p}
for(i in 0:n+1) {
for(j in 0:n+1) {
if (List_1[i]==List_2[j]) {x[length(x)+1]<-((i-1)+(j-1)*n)}
}
}
return(min(x))
}
CRA<-function(S) #Algorithm of chinese remainder theorem
{
r<-S[,1] # matrix S express below sysyem.
mod<-S[,2] # x = r[1] (mod mod[1])
n<-length(r) # x = r[2] (mod mod[2])
# x = r[3] (mod mod[3])
A<-seq(r[1],to=mod[1]*mod[2],by=mod[1])
for(i in 2:n)
{
B=seq(r[i],to=mod[1]*mod[i],by=mod[i])
r[1]=min(A[A %in% B])
mod[1]=mod[1]*mod[i]
if (i<n) {A=seq(r[1],to=mod[1]*mod[i+1],by=mod[1])}
}
return(r[1])
}
PHA<-function(g,h,p){
N<-order(g,p)
m_<-table(factorize(N))
m_<-rbind(as.numeric(names(m_)),m_)
m_<-c(data.frame(m_)[1,]^data.frame(m_)[2,])
y_<-numeric(0)
for(i in 1:length(m_)){
g_i<-FPM(g,N/m_[i],p)
h_i<-FPM(h,N/m_[i],p)
y_[i]<-shanks(g_i,h_i,p)
}
return(CRA(cbind(y_,m_)))
}
PHA(7,166,433)
FPM(7,47,433)
PHA(10,243278,746497)
FPM(10,223755,746497)
PHA(2,39183497,41022299)
FPM(2,33703314,41022299)
The result of running the above code is as follows, and it has been checked that it works correctly by verifying with exponentiation by squaring.