﻿ RSA算法的實現——java版_電腦知識網

# RSA算法的實現——java版

2013-11-23 17:54:41  來源: Javascript

package rsa;

import javamathBigInteger;

public class RSA {
private long pqedn;
public RSA(){
int pIndex = (int)(Mathrandom()*);
int qIndex;
int eIndex;
do{
qIndex = (int)(Mathrandom()*);
}
while(qIndex==pIndex);
do{
eIndex = (int)(Mathrandom()*);
}
while(eIndex==pIndex||eIndex==pIndex);
p = ;
q = ;
e = ;
n = p*q;
d = calculateD();
}
private long calculateD(){
long t = t = t = ;
long r = (p)*(q) m = rr = e r = ;
do{
long q = r/r;
r = rr*q;
if(r==)break;
t = t t*q;
while(t<){
t+=m;
}
if(t>=m){
t %= m;
}
r = r;
r = r;
t = t;
t = t;
}while(r!=);
if(r!=){
return ;
}
else{
return t;
}
}

public long getE() {
return e;
}
public long getN() {
return n;
}
public long getD() {
return d;
}
public BigInteger encode(BigInteger data){
}
public BigInteger decode(BigInteger code){
return pow(codee)mod(new BigInteger(n+));
}
public BigInteger pow(BigInteger datalong p){
data = datapow((int)p);
return data;
}
public static void main(String args[]){
RSA rsa = new RSA();

BigInteger data = new BigInteger();
long oldtime = SystemcurrentTimeMillis();
BigInteger code = rsaencode(data);
long newtime = SystemcurrentTimeMillis();
double codetime = ((double)(newtimeoldtime))/;
oldtime = SystemcurrentTimeMillis();
newtime = SystemcurrentTimeMillis();
double decodetime = ((double)(newtimeoldtime))/;
Systemoutprintln(publickKey:+rsae);
Systemoutprintln(N:+rsan);
Systemoutprintln(data:+data);
Systemoutprintln(code:+code+ time:+codetime);
Systemoutprintln(decode:+decode+ time:+decodetime);

}

}

From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/25327.html
推薦文章