RSA算法的实现方法——Java版放送
来源:长理培训发布时间:2017-12-22 10:18:53
一开始不知道有BigInteger这个大数类,居然自己去实现了一个,写了大数加法后,才发现有现成的T_T
以下是引用片段:
import java.math.BigInteger;
public class RSA {
public RSA(){
int qIndex;
do{
}
do{
}
p = 1033;
e = 29437;
d = calculateD();
private long calculateD(){
long r0 = (p-1)*(q-1), m = r0,r1 = e ,r2 = -1;
long q = r0/r1;
if(r2==0)break;
while(t2< 0){
} =m){
}
r1 = r2;
t1 = t2;
if(r1!=1){
}
return t2;
}
public long getE() {
}
return n;
public long getD() {
}
return pow(data,d).mod(new BigInteger(n+""));
public BigInteger decode(BigInteger code){
}
data = data.pow((int)p);
}
RSA rsa = new RSA();
BigInteger data = new BigInteger("222222");
BigInteger code = rsa.encode(data);
double codetime = ((double)(newtime-oldtime))/1000;
BigInteger decode = rsa.decode(code);
double decodetime = ((double)(newtime-oldtime))/1000;
System.out.println("publickKey:"+rsa.e);
System.out.println("data:"+data);
System.out.println("decode:"+decode+" time:"+decodetime);
}
}
|
点击加载更多评论>>