Question

I need to compute the product of two BigIntegers raised to BigIntegers modular a prime.

I'm computing - y^r * r^s (mod p).

The code I'm using works, but I can't help feeling that it is performing unnecessary calculations, which are pretty expensive when large BigIntegers are involved.

BigInteger v1A = y.modPow(r, p);
BigInteger v1B = r.modPow(s, p);
BigInteger v1 = v1A.multiply(v1B).mod(p);

Ideally I'd like a way to calculate v1 in one go. Is this possible?

Était-ce utile?

La solution

Assuming that the methods that you're using are efficient, I don't see a faster way to do this, but I'm no expert. Of course, you could consolidate your code to:

BigInteger v1 = (y.modPow(r,p)).multiply(r.modPow(s,p)).mod(p)

but that's the exact same as your code.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top