Java 如何分解170位长的BigInteger
我需要对170位长的整数进行因子分解,我知道这个数字有2个因子。我尝试过Pollard Rho算法,但不幸的是,这个锤子不够大,无法粉碎它。算法没有结束。我犯了什么错误吗Java 如何分解170位长的BigInteger,java,factorization,Java,Factorization,我需要对170位长的整数进行因子分解,我知道这个数字有2个因子。我尝试过Pollard Rho算法,但不幸的是,这个锤子不够大,无法粉碎它。算法没有结束。我犯了什么错误吗 import java.math.BigInteger; import java.security.SecureRandom; public class PollardRho { private final static BigInteger ZERO = new BigInteger("0"); priva
import java.math.BigInteger;
import java.security.SecureRandom;
public class PollardRho {
private final static BigInteger ZERO = new BigInteger("0");
private final static BigInteger ONE = new BigInteger("1");
private final static BigInteger TWO = new BigInteger("2");
private final static SecureRandom random = new SecureRandom();
public static BigInteger rho(BigInteger N) {
BigInteger divisor;
BigInteger c = new BigInteger(N.bitLength(), random);
BigInteger x = new BigInteger(N.bitLength(), random);
BigInteger xx = x;
// check divisibility by 2
if (N.mod(TWO).compareTo(ZERO) == 0)
return TWO;
do {
x = x.multiply(x).mod(N).add(c).mod(N);
xx = xx.multiply(xx).mod(N).add(c).mod(N);
xx = xx.multiply(xx).mod(N).add(c).mod(N);
divisor = x.subtract(xx).gcd(N);
} while ((divisor.compareTo(ONE)) == 0);
return divisor;
}
public static void factor(BigInteger N) {
if (N.compareTo(ONE) == 0)
return;
if (N.isProbablePrime(20)) {
System.out.println(N);
return;
}
BigInteger divisor = rho(N);
factor(divisor);
factor(N.divide(divisor));
}
public static void main(String[] args) {
BigInteger N = new BigInteger(
"46862651776313668832684618638310007043245135907468247470585960688008180534742005269578548831878148535158738789789506710579367525183636389872513135592162572724499935530721");
factor(N);
}
}
你的问题到底是什么?这个代码不起作用吗?(如果是的话,请详细描述您的期望和is的实际功能)或者您是否要求代码审查?(在这种情况下,是应该去的地方,而不是stackoverflow.com)你想做什么,破解RSA私钥?“算法没有结束。”在说出这句话之前,你等了多少小时/天/月/年?如果对170位长的整数进行FCTORING很容易,我们就会遇到大麻烦。@StephaneM我等了几分钟。用一个较小的数字测试你的代码。生成两个10位数的素数并将它们相乘。您的代码是否正确分解了产品?需要多长时间?对两个20位素数执行相同的操作。再来一次。这将让你估计需要等待多长时间才能得到当前问题的答案。