BigIntegerValue.pow(整数値)
Javaの指数は整数ですが、Biginteger値がありました。
署名を検証しようとしました GOST 3410、私はこのコードを取得しましたが、長すぎます..
アイデアはありますか?P と Q を取得するために、私は弾むキャッスルを使用しています..しかし、値を確認する方法がわからないため、弾むキャッスルで確認する方法がわかりません..ありがとう。
public static BigInteger pow_manual(BigInteger x, BigInteger y) {
if (y.compareTo(BigInteger.ZERO) < 0) {
throw new IllegalArgumentException();
}
BigInteger z = x; // z will successively become x^2, x^4, x^8, x^16, x^32...
BigInteger result = BigInteger.ONE;
byte[] bytes = y.toByteArray();
for (int i = bytes.length - 1; i >= 0; i--) {
byte bits = bytes[i];
for (int j = 0; j < 8; j++) {
if ((bits & 1) != 0) {
result = result.multiply(z);
}
// short cut out if there are no more bits to handle:
if ((bits >>= 1) == 0 && i == 0) {
return result;
}
z = z.multiply(z);
}
}
return result;
}