Pregunta

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?

¿Fue útil?

Solución

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);

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top