-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPollardRho.java
More file actions
50 lines (43 loc) · 1.15 KB
/
PollardRho.java
File metadata and controls
50 lines (43 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package Crypto;
import java.math.BigInteger;
public class PollardRho {
public static BigInteger euclid(BigInteger a,BigInteger b){
if(a.compareTo(BigInteger.ZERO)==0)
return b;
while(b.compareTo(BigInteger.ZERO)!=0){
if(a.compareTo(b)==1)
a=a.subtract(b);
else
b=b.subtract(a);
}
return a;
}
public static BigInteger function(BigInteger x,BigInteger modulo){
x=x.multiply(x);
x=x.add(new BigInteger("40282366920938463463374607431768211457"));
return x.mod(modulo);
}
public static void main(String[]args){
BigInteger num=new BigInteger("2");
num=num.pow(128);
num=num.add(BigInteger.ONE);
System.out.println(num);
System.out.println(factor(num));
//System.out.println(euclid(new BigInteger(""+378),new BigInteger(""+526)));
}
public static BigInteger factor(BigInteger num){
BigInteger x,y,d;
x=new BigInteger("2");
y=new BigInteger("2");
d=new BigInteger("1");
while(d.equals(BigInteger.ONE)){
x=function(x,num);
y=function(y,num);
y=function(y,num);
d=euclid((x.subtract(y)).abs(),num);
}
if(d==num)
return null;
return d;
}
}