I am designing an implementation of RSA . I recorded computation times in Java by using System.currentTimeMillis()
. It returned an encryption time of 0.05 ms and decryption time of 0.55 ms, or a ratio of 1:11.
This seems like a large difference. Is it supposed to be this way?
//here my key has 256 bits
for (;;) {
long begin = System.currentTimeMillis();
for (int i = 0; i < num; i++) {
decrypt();
}
long end = System.currentTimeMillis();
long time = end - begin;
if (time >= 10000) {
System.out.printf("Average Encryption takes: %.2f ms\n",
(double) time / num);
break;
}
num *= 2;
}
p = BigInteger.probablePrime(128, random);
q = BigInteger.probablePrime(128, random);
N=(p.subtract(one)).multiply(q.subtract(one));
e=BigInteger.probablePrime(32, random);
d=e.modInverse(N);
private void encrypt()
{
C= M.modPow(e,N);
}
private void decrypt()
{
RM = C.modPow(d, N);
}