Java BigInteger Calculate modPowByte(byte[] arg, BigInteger e, BigInteger n)

Here you can find the source of modPowByte(byte[] arg, BigInteger e, BigInteger n)

Description

mod Pow Byte

License

Open Source License

Declaration

public static byte[] modPowByte(byte[] arg, BigInteger e, BigInteger n) 

Method Source Code


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

import java.math.BigInteger;

public class Main {
    public static byte[] modPowByte(byte[] arg, BigInteger e, BigInteger n) {
        BigInteger source = new BigInteger(1, arg);
        BigInteger result = source.modPow(e, n);
        return getBytesWithoutSign(result);
    }//from   www  .  ja  v a 2  s .  c  o m

    private static byte[] getBytesWithoutSign(BigInteger arg) {
        byte[] sourceArray = arg.toByteArray();
        if (sourceArray[0] != 0) {
            return sourceArray;
        } else {
            byte[] withoutSign = new byte[sourceArray.length - 1];
            System.arraycopy(sourceArray, 1, withoutSign, 0, withoutSign.length);
            return withoutSign;
        }
    }
}

Related

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