Reformulate the equation for me faster in java

I'm working on encryption, and for the private key metric dyou need to multiply d by e and take the mod of a different number, and the remainder is 1. I already have a function:

private void genD() {
        d = e / 2;
        // solve for d given d*e = 1 (mod eN)
        while ((d * e) % eN != 1) {
            d++;
        }
}

what I have now is obviously a rude way of doing things, going through each number until it works. I know that the equation does its job by connecting the numbers using the working example found here , but VERY VERY VERY slow using the for numbers I create. Logically, I feel that there is a way to do this much faster, but I can’t think about how?

Any help is appreciated! Thanks in advance:)

+4
1

, , Java:

 BigInteger.valueOf(e).modInverse(BigInteger.valueOf(eN)).intValue();

- http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Modular_integers.

+6

All Articles