I am implementing RSA in java using BigInteger and I have a method to return a random relative prime number based on the modulus m.
The method looks like this:
BigInteger prime = new BigInteger(m.bitLength(),rnd);
while (prime.compareTo(BigInteger.ZERO) <= 0 || !prime.gcd(m).equals(BigInteger.ONE) )
{
prime = new BigInteger(m.bitLength(),rnd);
}
Is there anyway to make this more efficient? I dont know if recreating an object like this is bad or not.