rsa - takes to slow

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.
 
M

Martin

Ditch Java and go native.
Slow has been the byname of Java since day 1 and it still is after 8 years.
Hyped up crap is what it is.

Rgds Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top