Here you can find the source of multi_exponent(BigInteger[] base, BigInteger[] exponent, BigInteger modulus)
Parameter | Description |
---|---|
base | the bases |
exponent | the exponents |
modulus | a parameter |
public static BigInteger multi_exponent(BigInteger[] base, BigInteger[] exponent, BigInteger modulus)
//package com.java2s; // modify it under the terms of the GNU General Public License as import java.math.BigInteger; public class Main { /**/*w w w .jav a2s . c o m*/ * * Compute the multi-exponent {@code base^exponent (modulo * modulus)}. * <P> * * Asserts that the {@code base} and {@code exponent} array have * the same length. * * @param base the bases * @param exponent the exponents * @param modulus * @return the exponent {@code base[0]^exponent[0] * * base[1]^exponent[1] * ... (modulo modulus)} */ public static BigInteger multi_exponent(BigInteger[] base, BigInteger[] exponent, BigInteger modulus) { assert base.length == exponent.length; BigInteger res = BigInteger.ONE; for (int i = 0; i < base.length; i++) res = res.multiply(base[i].modPow(exponent[i], modulus)).mod(modulus); return res; } }