本文整理了Java中java.math.BigInteger.mod()
方法的一些代码示例,展示了BigInteger.mod()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.mod()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:mod
[英]Returns a BigInteger whose value is this mod m. The modulus m must be positive. The result is guaranteed to be in the interval [0, m) (0 inclusive, m exclusive). The behavior of this function is not equivalent to the behavior of the % operator defined for the built-in int's.
[中]返回一个BigInteger,其值为该模m。模m必须为正。结果保证在区间[0,m](0包括,m不包括)内。此函数的行为与为内置int定义的%运算符的行为不同。
代码示例来源:origin: stackoverflow.com
int nlen = n.bitLength();
BigInteger nm1 = n.subtract(BigInteger.ONE);
BigInteger r, s;
do {
s = new BigInteger(nlen + 100, rnd);
r = s.mod(n);
} while (s.subtract(r).add(nm1).bitLength() >= nlen + 100);
// result is in 'r'
代码示例来源:origin: stackoverflow.com
BigInteger val = new BigInteger("1254789363254125");
public boolean odd(BigInteger val) {
if(!val.mod(new BigInteger("2")).equals(BigInteger.ZERO))
return true;
return false;
}
代码示例来源:origin: ethereum/ethereumj
@Override public Fp squared() { return new Fp(v.multiply(v).mod(P)); }
@Override public Fp dbl() { return new Fp(v.add(v).mod(P)); }
代码示例来源:origin: stackoverflow.com
public static void main(String... args) {
BigInteger fact = fact(100);
System.out.println("fact(100) = " + fact);
System.out.println("fact(100).longValue() = " + fact.longValue());
System.out.println("fact(100).intValue() = " + fact.intValue());
int powerOfTwoCount = 0;
BigInteger two = BigInteger.valueOf(2);
while (fact.compareTo(BigInteger.ZERO) > 0 && fact.mod(two).equals(BigInteger.ZERO)) {
powerOfTwoCount++;
fact = fact.divide(two);
}
System.out.println("fact(100) powers of two = " + powerOfTwoCount);
}
private static BigInteger fact(long n) {
BigInteger result = BigInteger.ONE;
for (long i = 2; i <= n; i++)
result = result.multiply(BigInteger.valueOf(i));
return result;
}
代码示例来源:origin: i2p/i2p.i2p
protected byte[] engineSign() throws SignatureException {
BigInteger elgp = key.getParams().getP();
BigInteger pm1 = elgp.subtract(BigInteger.ONE);
BigInteger elgg = key.getParams().getG();
BigInteger x = ((ElGamalPrivateKey) key).getX();
boolean ok;
do {
k = new BigInteger(2048, RandomSource.getInstance());
ok = k.compareTo(pm1) == -1;
ok = ok && k.compareTo(BigInteger.ONE) == 1;
ok = ok && k.gcd(pm1).equals(BigInteger.ONE);
} while (!ok);
BigInteger r = elgg.modPow(k, elgp);
BigInteger kinv = k.modInverse(pm1);
BigInteger h = new NativeBigInteger(1, data);
BigInteger s = (kinv.multiply(h.subtract(x.multiply(r)))).mod(pm1);
代码示例来源:origin: apache/zeppelin
BigInteger base = new BigInteger("" + DICTIONARY.length);
int exponent = 1;
BigInteger remaining = new BigInteger(value.toString());
while (true) {
BigInteger b = remaining.mod(a); // 119 % 16 = 7 | 112 % 256 = 112
BigInteger c = base.pow(exponent - 1);
BigInteger d = b.divide(c);
remaining = remaining.subtract(b); // 119 - 7 = 112 | 112 - 112 = 0
if (remaining.equals(BigInteger.ZERO)) {
break;
代码示例来源:origin: web3j/web3j
byte[] chainCode = Arrays.copyOfRange(i, 32, 64);
Arrays.fill(i, (byte) 0);
BigInteger ilInt = new BigInteger(1, il);
Arrays.fill(il, (byte) 0);
ECPoint ki = Sign.publicPointFromPrivate(ilInt).add(getPublicKeyPoint());
byte[] chainCode = Arrays.copyOfRange(i, 32, 64);
Arrays.fill(i, (byte) 0);
BigInteger ilInt = new BigInteger(1, il);
Arrays.fill(il, (byte) 0);
BigInteger privateKey = getPrivateKey().add(ilInt).mod(Sign.CURVE.getN());
代码示例来源:origin: DiUS/java-faker
private static String calculateIbanChecksum(String countryCode, String basicBankAccountNumber) {
String basis = basicBankAccountNumber + countryCode + "00";
StringBuilder sb = new StringBuilder();
char[] characters = basis.toLowerCase().toCharArray();
for (char c : characters) {
if (Character.isLetter(c)) {
sb.append(String.valueOf((c - 'a') + 10));
} else {
sb.append(c);
}
}
int mod97 = new BigInteger(sb.toString()).mod(BigInteger.valueOf(97L)).intValue();
return StringUtils.leftPad(String.valueOf(98 - mod97), 2, '0');
}
代码示例来源:origin: aws-amplify/aws-sdk-android
public AuthenticationHelper(String userPoolName) {
do {
a = new BigInteger(EPHEMERAL_KEY_LENGTH, SECURE_RANDOM).mod(N);
A = GG.modPow(a, N);
} while (A.mod(N).equals(BigInteger.ZERO));
if (userPoolName.contains("_")) {
poolName = userPoolName.split("_", 2)[1];
} else {
poolName = userPoolName;
}
}
代码示例来源:origin: robovm/robovm
/**
* Returns a {@code BigInteger} whose value is {@code
* pow(this, exponent) mod modulus}. The modulus must be positive. The
* result is guaranteed to be in the interval {@code [0, modulus)}.
* If the exponent is negative, then
* {@code pow(this.modInverse(modulus), -exponent) mod modulus} is computed.
* The inverse of this only exists if {@code this} is relatively prime to the modulus,
* otherwise an exception is thrown.
*
* @throws NullPointerException if {@code modulus == null} or {@code exponent == null}.
* @throws ArithmeticException if {@code modulus < 0} or if {@code exponent < 0} and
* not relatively prime to {@code modulus}.
*/
public BigInteger modPow(BigInteger exponent, BigInteger modulus) {
if (modulus.signum() <= 0) {
throw new ArithmeticException("modulus.signum() <= 0");
}
int exponentSignum = exponent.signum();
if (exponentSignum == 0) { // OpenSSL gets this case wrong; http://b/8574367.
return ONE.mod(modulus);
}
BigInteger base = exponentSignum < 0 ? modInverse(modulus) : this;
return new BigInteger(BigInt.modExp(base.getBigInt(), exponent.getBigInt(), modulus.getBigInt()));
}
代码示例来源:origin: i2p/i2p.i2p
@Test
public void squareAndDoubleReturnsCorrectResult() {
for (int i=0; i<1000; i++) {
// Arrange:
final FieldElement f1 = getRandomFieldElement();
final BigInteger b1 = toBigInteger(f1);
// Act:
final FieldElement f2 = f1.squareAndDouble();
final BigInteger b2 = toBigInteger(f2).mod(getQ());
// Assert:
Assert.assertThat(b2, IsEqual.equalTo(b1.multiply(b1).multiply(new BigInteger("2")).mod(getQ())));
}
}
代码示例来源:origin: i2p/i2p.i2p
public byte[] multiplyAndAdd(byte[] a, byte[] b, byte[] c) {
return enc.encode(enc.toBigInteger(a).multiply(enc.toBigInteger(b)).add(enc.toBigInteger(c)).mod(l));
}
代码示例来源:origin: ethereum/ethereumj
@Override public Fp add(Fp o) { return new Fp(this.v.add(o.v).mod(P)); }
@Override public Fp mul(Fp o) { return new Fp(this.v.multiply(o.v).mod(P)); }
代码示例来源:origin: RUB-NDS/TLS-Attacker
public static BigInteger intceildiv(BigInteger c, BigInteger d) {
if (c.mod(d).equals(BigInteger.ZERO)) {
return intfloordiv(c, d);
} else {
return intfloordiv(c, d).add(BigInteger.ONE);
}
}
代码示例来源:origin: i2p/i2p.i2p
BigInteger y1p = ELGPM1.subtract(a);
System.arraycopy(encrypted, ELG_HALF_LENGTH, buf, 0, ELG_HALF_LENGTH);
BigInteger d = new NativeBigInteger(1, buf);
BigInteger m = ya.multiply(d);
m = m.mod(CryptoConstants.elgp);
byte val[] = m.toByteArray();
int i;
代码示例来源:origin: ethereum/ethereumj
@Override public Fp sub(Fp o) { return new Fp(this.v.subtract(o.v).mod(P)); }
@Override public Fp squared() { return new Fp(v.multiply(v).mod(P)); }
代码示例来源:origin: java-json-tools/json-schema-validator
@Override
public void validate(final Processor<FullData, FullData> processor,
final ProcessingReport report, final MessageBundle bundle,
final FullData data)
throws ProcessingException
{
final BigInteger value
= data.getInstance().getNode().bigIntegerValue();
/*
* We use a plain list to store failed divisors: remember that the
* digested form was built with divisors in order, we therefore
* only need insertion order, and a plain ArrayList guarantees that.
*/
final List<BigInteger> failed = Lists.newArrayList();
for (final BigInteger divisor: divisors)
if (!value.mod(divisor).equals(BigInteger.ZERO))
failed.add(divisor);
if (failed.isEmpty())
return;
/*
* There are missed divisors: report.
*/
report.error(newMsg(data, bundle, "missingDivisors")
.put("divisors", divisors).put("failed", failed));
}
代码示例来源:origin: jphp-group/jphp
BigInteger bigInt = new BigInteger(String.valueOf(value));
bigInt = bigInt.add(BIG_2_64);
while (bigInt.compareTo(BigInteger.ZERO) != 0) {
int digit = bigInt.mod(BIG_TEN).intValue();
代码示例来源:origin: stackoverflow.com
BigInteger val = new BigInteger("1254789363254125");
public boolean odd(BigInteger val) {
return !val.mod(new BigInteger("2")).equals(BigInteger.ZERO));
}
代码示例来源:origin: ethereum/ethereumj
void testAddMod(String v1, String v2, String v3) {
DataWord dv1 = DataWord.of(Hex.decode(v1));
DataWord dv2 = DataWord.of(Hex.decode(v2));
DataWord dv3 = DataWord.of(Hex.decode(v3));
BigInteger bv1 = new BigInteger(v1, 16);
BigInteger bv2 = new BigInteger(v2, 16);
BigInteger bv3 = new BigInteger(v3, 16);
DataWord actual = dv1.addmod(dv2, dv3);
BigInteger br = bv1.add(bv2).mod(bv3);
assertEquals(actual.value(), br);
}
内容来源于网络,如有侵权,请联系作者删除!