S
stefan.z
hello,
I m trying to create programm that uses implementation of RSA algorithm
shown below :
public class Rsa
{
private BigInteger n, d, e;
private BigInteger p, q;
public Rsa(int bitlen)
{
//SecureRandom r = new SecureRandom();
Random r = new Random();
p = new BigInteger(bitlen / 2, 100, r);
q = new BigInteger(bitlen / 2, 100, r);
n = p.multiply(q);
BigInteger m = (p.subtract(BigInteger.ONE))
.multiply(q.subtract(BigInteger.ONE));
e = new BigInteger("3");
while (m.gcd(e).intValue() > 1) {
e = e.add(new BigInteger("2"));
}
d = e.modInverse(m);
}
public BigInteger encrypt(BigInteger message)
{
return message.modPow(e, n);
}
public BigInteger decrypt(BigInteger message)
{
return message.modPow(d, n);
}
}
the problem is that program runs too slow ... take a look at `encrypt`
method ... it rasing M to e and dividing result modulo n (M ^ e %n) ...
because of `BigInteger message length` ( > 100 - depends on bitlen) and
also huge value of exponent e & divider n ...
I m dividing message into small units - 3 chars length, converting it to
digit ( digit <= 10^6) and encrypting each part. so if the message is
long it takes so much time to calculate it ...
what should I do to improve performance ?
greeting
w.w.
I m trying to create programm that uses implementation of RSA algorithm
shown below :
public class Rsa
{
private BigInteger n, d, e;
private BigInteger p, q;
public Rsa(int bitlen)
{
//SecureRandom r = new SecureRandom();
Random r = new Random();
p = new BigInteger(bitlen / 2, 100, r);
q = new BigInteger(bitlen / 2, 100, r);
n = p.multiply(q);
BigInteger m = (p.subtract(BigInteger.ONE))
.multiply(q.subtract(BigInteger.ONE));
e = new BigInteger("3");
while (m.gcd(e).intValue() > 1) {
e = e.add(new BigInteger("2"));
}
d = e.modInverse(m);
}
public BigInteger encrypt(BigInteger message)
{
return message.modPow(e, n);
}
public BigInteger decrypt(BigInteger message)
{
return message.modPow(d, n);
}
}
the problem is that program runs too slow ... take a look at `encrypt`
method ... it rasing M to e and dividing result modulo n (M ^ e %n) ...
because of `BigInteger message length` ( > 100 - depends on bitlen) and
also huge value of exponent e & divider n ...
I m dividing message into small units - 3 chars length, converting it to
digit ( digit <= 10^6) and encrypting each part. so if the message is
long it takes so much time to calculate it ...
what should I do to improve performance ?
greeting
w.w.