林内的BigInteger显影用java这就需要找到两个大整数(Y和Z)的应用程序:java查找满足该两个条件的特定范围
Y^k < N and Z^j < N < Z^(j+1)
N,K和j是已知的。 N是一个大整数(1024bit)。
我目前的实现是通过选择一个随机的BigInteger来检测Y和Z,并测试条件是否满足。但问题是,有时需要很长时间才能找到解决方案,或者根本找不到解决方案(可能bitSize未正确计算)。 有什么办法可以加快速度吗?
代码:
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;
}
我没有提到我需要几个解决方案。我怎么修改二进制搜索,所以我不总是得到相同的解决方案? – blejzz
您可以搜索'Z^j