@Test
public void testModInverse() {

  assertEquals(BigInteger.valueOf(2),
      modInverse(BigInteger.valueOf(3), BigInteger.valueOf(5)));
  Random rnd = new Random();
  BigInteger m = new BigInteger(1024, rnd).nextProbablePrime();
  for (int i = 0; i < 100; i++) {
    BigInteger x = new BigInteger(1023, rnd);
    assertEquals(x.modInverse(m), modInverse(x, m));
  }
}