Java BigInteger Calculate multi_exponent(BigInteger[] base, BigInteger[] exponent, BigInteger modulus)

Here you can find the source of multi_exponent(BigInteger[] base, BigInteger[] exponent, BigInteger modulus)

Description

Compute the multi-exponent base^exponent (modulo modulus) .

License

Open Source License

Parameter

Parameter Description
base the bases
exponent the exponents
modulus a parameter

Return

the exponent base[0]^exponent[0] base[1]^exponent[1] * ... (modulo modulus)

Declaration

public static BigInteger multi_exponent(BigInteger[] base, BigInteger[] exponent, BigInteger modulus) 

Method Source Code

//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;
    }
}

Related

  1. modPow(BigInteger base, BigInteger e, BigInteger m)
  2. modPowByte(byte[] arg, BigInteger e, BigInteger n)
  3. modPowLong(BigInteger n, long exponent, BigInteger modulo)
  4. mods(BigInteger v, BigInteger m)
  5. modulus(BigInteger value, BigInteger divider, int modulo, int... weight)
  6. multiply(BigInteger x, BigInteger y)
  7. negative(BigInteger n)
  8. normalizarParaBigInteger(Number numero, RoundingMode modo)
  9. numberToIpv4(BigInteger ipNumber)