BigInteger: modPow(BigInteger exponent, BigInteger m)

BigInteger modPow(BigInteger exponent, BigInteger m)
Returns a BigInteger whose value is (thisexponent mod m).

import java.math.BigInteger;
import java.security.SecureRandom;

public class Main {
  public static void main(String[] args) throws Exception {
    int bitLength = 512; // 512 bits
    SecureRandom rnd = new SecureRandom();
    int certainty = 90; // 1 - 1/2(90) certainty
    System.out.println("BitLength : " + bitLength);
    BigInteger mod = new BigInteger(bitLength, certainty, rnd);
    BigInteger exponent = BigInteger.probablePrime(bitLength, rnd);
    BigInteger n = BigInteger.probablePrime(bitLength, rnd);

    BigInteger result = n.modPow(exponent, mod);
    System.out.println("Number ^ Exponent MOD Modulus = Result");
    System.out.println("Number");
    System.out.println(n);
    System.out.println("Exponent");
    System.out.println(exponent);
    System.out.println("Modulus");
    System.out.println(mod);
    System.out.println("Result");
    System.out.println(result);
  }
}
Home 
  Java Book 
    Essential Classes  

BigInteger:
  1. BigInteger class
  2. BigInteger.TEN
  3. BigInteger.ZERO
  4. Constructor
  5. BigInteger: add(BigInteger val)
  6. BigInteger: andNot(BigInteger val)
  7. BigInteger: bitLength()
  8. BigInteger: clearBit(int n)
  9. BigInteger: divide(BigInteger val)
  10. BigInteger: doubleValue()
  11. BigInteger: flipBit(int n)
  12. BigInteger: isProbablePrime(int certainty)
  13. BigInteger: modPow(BigInteger exponent, BigInteger m)
  14. BigInteger: multiply(BigInteger val)
  15. BigInteger: negate()
  16. BigInteger: not()
  17. BigInteger: or(BigInteger val)
  18. BigInteger: probablePrime(int bitLength, Random rnd)
  19. BigInteger: pow(int exponent)
  20. BigInteger: setBit(int n)
  21. BigInteger: shiftLeft(int n)
  22. BigInteger: shiftRight(int n)
  23. BigInteger: subtract(BigInteger val)
  24. BigInteger: testBit(int n)
  25. BigInteger: toByteArray()
  26. BigInteger: toString()
  27. BigInteger: toString(int radix)
  28. BigInteger: valueOf(long val)
  29. BigInteger: xor(BigInteger val)