Java BigInteger Calculate modPow(BigInteger base, BigInteger e, BigInteger m)

Here you can find the source of modPow(BigInteger base, BigInteger e, BigInteger m)

Description

mod Pow

License

Open Source License

Declaration

public static BigInteger modPow(BigInteger base, BigInteger e, BigInteger m) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigInteger;

public class Main {
    public static BigInteger modPow(BigInteger base, BigInteger e, BigInteger m) {
        BigInteger result;//from  w  ww  .j  a  v a 2  s. c o  m

        result = BigInteger.ONE;
        base = base.mod(m);

        for (int i = 0; i < e.bitLength(); ++i) {
            if (e.testBit(i)) {
                result = result.multiply(base).mod(m);
            }
            base = base.multiply(base).mod(m);
        }
        return result;
    }
}

Related

  1. length(BigInteger bi)
  2. listToBigInteger(List list)
  3. log2(BigInteger x)
  4. maskBits(BigInteger value, int bits)
  5. min(BigInteger a, BigInteger b)
  6. modPowByte(byte[] arg, BigInteger e, BigInteger n)
  7. modPowLong(BigInteger n, long exponent, BigInteger modulo)
  8. mods(BigInteger v, BigInteger m)
  9. modulus(BigInteger value, BigInteger divider, int modulo, int... weight)