Im developing an application with java which needs to find two big integers (Y and Z) that meet this two conditions:
Y^k < N and Z^j < N < Z^(j+1)
N, k and j are known. N is a big integer(1024bit).
My current implementations finds Y and Z by choosing a random BigInteger and tests if the conditions are met. But the problem is that sometimes it takes really long to find the solution or it doesn't find one at all (probably the bitSize isn't correctly computed). Is there any way i could speed this up?
The code:
BigInteger getMessage(int bitSize, int lowerBound, int upperBound, BigInteger module)
{
boolean foundOne = false;
BigInteger candidate = null;
while( !foundOne )
{
candidate = new BigInteger(bitSize,random);
foundOne = (upperBound == 0 || candidate.pow(upperBound).compareTo(module) > 0 ) && (lowerBound == 0 || candidate.pow(lowerBound).compareTo(module) < 0);
}
return candidate;
}