문제

while(true) {
    if(((d.multiply(e)).mod(phi1)).equals(BigInteger.ONE))
        break;
    d.add(BigInteger.ONE);
}

I have the following code in my program, which means that

while(true) {
    if((d*e)%phil==1) 
        break;
    d++;
}

Here, e=17, phil=12816 and d=1 initially.

But even after waiting for a long time, the loop is still executing. What could be the mistake?

도움이 되었습니까?

해결책

BigInteger is immutable and all operations on it return a new instance instead of modifying the current one. Thus d.add(BigInteger.ONE); does not change the value of d.

To fix the issue write: d = d.add(BigInteger.ONE);

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top