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){
return pow(datad)mod(new BigInteger(n+));
}
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();
BigInteger decode = rsadecode(code);
newtime = SystemcurrentTimeMillis();
double decodetime = ((double)(newtimeoldtime))/;
Systemoutprintln(privateKey:+rsad);
Systemoutprintln(publickKey:+rsae);
Systemoutprintln(N:+rsan);
Systemoutprintln(data:+data);
Systemoutprintln(code:+code+ time:+codetime);
Systemoutprintln(decode:+decode+ time:+decodetime);
}
}