public void testmodInverseNeg2(){
  byte aBytes[]={-15,24,123,57,-15,24,123,57,-15,24,123,57};
  byte mBytes[]={122,2,4,122,2,4};
  byte rBytes[]={85,47,127,4,-128,45};
  BigInteger aNumber=new BigInteger(aBytes);
  BigInteger modulus=new BigInteger(mBytes);
  BigInteger result=aNumber.modInverse(modulus);
  byte resBytes[]=new byte[rBytes.length];
  resBytes=result.toByteArray();
  for (int i=0; i < resBytes.length; i++) {
    assertTrue(resBytes[i] == rBytes[i]);
  }
  assertEquals("incorrect sign",1,result.signum());
}

public void testmodInverseNeg2 ( ) { byte aBytes [ ] = { - 15 , 24 , 123 , 57 , - 15 , 24 , 123 , 57 , - 15 , 24 , 123 , 57 } ; byte mBytes [ ] = { 122 , 2 , 4 , 122 , 2 , 4 } ; byte rBytes [ ] = { 85 , 47 , 127 , 4 , - 128 , 45 } ; BigInteger aNumber = new BigInteger ( aBytes ) ; BigInteger modulus = new BigInteger ( mBytes ) ; BigInteger result = aNumber . modInverse ( modulus ) ; byte resBytes [ ] = new byte [ rBytes . length ] ; resBytes = result . toByteArray ( ) ; for ( int i = 0 ; i < resBytes . length ; i ++ ) { assertTrue ( resBytes [ i ] == rBytes [ i ] ) ; } assertEquals ( "incorrect sign" , 1 , result . signum ( ) ) ; }
modinverse : negative number ( another case : x < 0 )
