本文整理汇总了Java中java.math.BigInteger.ONE属性的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.ONE属性的具体用法?Java BigInteger.ONE怎么用?Java BigInteger.ONE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.ONE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decomposition
public static Map<BigInteger, BigInteger> decomposition(BigInteger n) throws Exception{
if(n.compareTo(BigInteger.ONE)!=1) throw new Exception("Not a positive integer.");
BigInteger max = bigIntSqRootCeil(n);
Map<BigInteger, BigInteger> map = new HashMap<BigInteger,BigInteger>();
for (BigInteger i = BigInteger.valueOf(2L); i.compareTo(max)<1;i=i.add(BigInteger.ONE)) {
boolean ipremier = true;
if(!i.equals(BigInteger.valueOf(2L)))
for (BigInteger j = BigInteger.valueOf(2L); j.compareTo(bigIntSqRootCeil(i))<1 && ipremier; j=j.add(BigInteger.ONE)){
if(i.mod(j).intValue()==0)ipremier=false;
}
if(!ipremier) continue;
if(n.mod(i).intValue()==0){
map.put(i, map.getOrDefault(i, BigInteger.ZERO).add(BigInteger.ONE));
n=n.divide(i);
max = bigIntSqRootCeil(n);
i=BigInteger.ONE;
}
}
map.put(n, map.getOrDefault(n, BigInteger.ZERO).add(BigInteger.ONE));
return map;
}
示例2: validateDHPublicKey
private static void validateDHPublicKey(BigInteger p,
BigInteger g, BigInteger y) throws InvalidKeyException {
// For better interoperability, the interval is limited to [2, p-2].
BigInteger leftOpen = BigInteger.ONE;
BigInteger rightOpen = p.subtract(BigInteger.ONE);
if (y.compareTo(leftOpen) <= 0) {
throw new InvalidKeyException(
"Diffie-Hellman public key is too small");
}
if (y.compareTo(rightOpen) >= 0) {
throw new InvalidKeyException(
"Diffie-Hellman public key is too large");
}
// y^q mod p == 1?
// Unable to perform this check as q is unknown in this circumstance.
// p is expected to be prime. However, it is too expensive to check
// that p is prime. Instead, in order to mitigate the impact of
// non-prime values, we check that y is not a factor of p.
BigInteger r = p.remainder(y);
if (r.equals(BigInteger.ZERO)) {
throw new InvalidKeyException("Invalid Diffie-Hellman parameters");
}
}
示例3: getGenerator
private BigInteger getGenerator(BigInteger q, BigInteger p, BigInteger pMinusOne) {
log.info("creating a generator");
BigInteger h = BigInteger.ONE;
boolean safe = false;
while (!safe) {
h = randomGenerator.randomInZq(p);
safe = modExp(h, TWO, p).compareTo(ONE) != 0
&& modExp(h, q, p).compareTo(ONE) != 0
&& pMinusOne.mod(h).compareTo(BigInteger.ZERO) != 0;
BigInteger gInv = safe ? h.modInverse(p) : ONE;
safe = safe && pMinusOne.mod(gInv).compareTo(BigInteger.ZERO) != 0;
}
log.info("generator created");
return modExp(h, TWO, p);
}
示例4: createConditionContextNode
@Test
public void createConditionContextNode() throws Exception {
final PublicKey bobPublicKey = bobKeyPair[0].getPublic();
new Expectations() {{
//noinspection ResultOfMethodCallIgnored
conditionContext.getOwnersAfter();
result = Collections.singletonList(bobKeyPair[0].getPublic());
//noinspection ResultOfMethodCallIgnored
conditionContext.getAssetQuantity();
result = BigInteger.ONE;
//noinspection ResultOfMethodCallIgnored
unsignedCreateTransaction.getConditionContexts();
result = Collections.singletonList(conditionContext);
}};
ObjectNode node =
SignedBigchaindbTransactionFactory.createConditionContextNode(0,
unsignedCreateTransaction,
Arrays.asList(aliceKeyPair));
assertEquals(3, node.size());
requireNumberValue(node, "amount", 1);
requireObjectValue(node, "condition", "details", "uri");
requireArrayValue(node, "public_keys",
jsonNodeFactory.textNode(Base58.base58Encode(bobKeyPair[0].getPublic().getEncoded())));
}
示例5: getMultiplicativeInverse
private long getMultiplicativeInverse(final long multiplier, final int nBits) {
BigInteger s = BigInteger.ZERO, previousS = BigInteger.ONE;
BigInteger t = BigInteger.ONE, previousT = BigInteger.ZERO;
BigInteger r = BigInteger.valueOf(multiplier), previousR = BigInteger.ONE.shiftLeft(nBits);
while (!BigInteger.ZERO.equals(r)) {
final BigInteger q = previousR.divide(r);
{
final BigInteger tempR = r;
r = previousR.subtract(q.multiply(r));
previousR = tempR;
}
{
final BigInteger tempS = s;
s = previousS.subtract(q.multiply(s));
previousS = tempS;
}
{
final BigInteger tempT = t;
t = previousT.subtract(q.multiply(t));
previousT = tempT;
}
}
return previousT.longValue();
}
示例6: valInt
@Override
public BigInteger valInt() {
String a = args.get(0).valStr();
String b = args.get(1).valStr();
if (a == null || b == null) {
nullValue = true;
return BigInteger.ZERO;
}
int value = a.compareTo(b);
nullValue = false;
return value == 0 ? BigInteger.ZERO : (value < 0 ? BigInteger.valueOf(-1) : BigInteger.ONE);
}
示例7: valInt
@Override
public BigInteger valInt() {
if (args.get(0).isNull()) {
return BigInteger.ZERO;
} else {
return BigInteger.ONE;
}
}
示例8: transactionGetFeeTest
@Test
public void transactionGetFeeTest() throws Exception {
// Prepare wallet to spend
StoredBlock block = new StoredBlock(makeSolvedTestBlock(blockStore, OTHER_ADDRESS), BigInteger.ONE, 1);
Transaction tx = createFakeTx(PARAMS, COIN, myAddress);
wallet.receiveFromBlock(tx, block, AbstractBlockChain.NewBlockType.BEST_CHAIN, 0);
// Create a transaction
SendRequest request = SendRequest.to(OTHER_ADDRESS, CENT);
request.feePerKb = Transaction.DEFAULT_TX_FEE;
wallet.completeTx(request);
assertEquals(Coin.valueOf(22700), request.tx.getFee());
}
示例9: factorial
/**
* Calculate n! Derived from http://chaosinmotion.com/blog/?p=622
*
* @param n
* @return
*/
public static final BigInteger factorial(int n) {
BigInteger ret;
if (n == 0)
return BigInteger.ONE;
if (null != (ret = CACHE_FACTORIAL.get(n)))
return ret;
ret = BigInteger.valueOf(n).multiply(factorial(n - 1));
CACHE_FACTORIAL.put(n, ret);
return ret;
}
示例10: cmpString
private BigInteger cmpString() {
String a = args.get(1).valStr();
String b = args.get(2).valStr();
String value = args.get(0).valStr();
if (!args.get(1).isNull() && !args.get(2).isNull()) {
return (value.compareTo(a) >= 0 && value.compareTo(b) <= 0) != negated ? BigInteger.ONE : BigInteger.ZERO;
}
return varNullValue(value, a, b);
}
示例11: cmpInt
private BigInteger cmpInt() {
long value = compareAsTemporalTimes ? args.get(0).valTimeTemporal() :
compareAsTemporalDates ? args.get(0).valDateTemporal() : args.get(0).valInt().longValue();
long a = getValByItem(args.get(1));
long b = getValByItem(args.get(2));
if (!args.get(1).isNull() && !args.get(2).isNull()) {
return (value >= a && value <= b) != negated ? BigInteger.ONE : BigInteger.ZERO;
}
return varNullValue(a, b, value);
}
示例12: genCert
public static X509Certificate genCert(KeyPair keyPair) throws NoSuchAlgorithmException, CertificateEncodingException, NoSuchProviderException, InvalidKeyException, SignatureException {
Date startDate = new Date(); // time from which certificate is valid
Date expiryDate = new Date(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY * 365); // time after which certificate is not valid
BigInteger serialNumber = BigInteger.ONE; // serial number for certificate
X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();
X500Principal dnName = new X500Principal("CN=Test CA Certificate");
certGen.setSerialNumber(serialNumber);
certGen.setIssuerDN(dnName);
certGen.setNotBefore(startDate);
certGen.setNotAfter(expiryDate);
certGen.setSubjectDN(dnName); // note: same as issuer
certGen.setPublicKey(keyPair.getPublic());
certGen.setSignatureAlgorithm("SHA256WITHECDSA");
return certGen.generate(keyPair.getPrivate(), "BC");
}
示例13: floor
@Override
public NumberWrapper floor(){
if (denominator.compareTo(BigInteger.ONE) == 0)
return this;
BigInteger[] bi = numerator.divideAndRemainder(denominator);
if (numerator.compareTo(BigInteger.ZERO) < 0){
return new Fraction(bi[0].subtract(BigInteger.ONE), BigInteger.ONE);
} else
return new Fraction(bi[0], BigInteger.ONE);
}
示例14: getProduct
/**
* Method for calculating the product of all ciphertexts .
*
* @param cipherText
* - BigInteger[]
* @return product - BigInteger
*/
public BigInteger getProduct(BigInteger[] cipherText) {
BigInteger mul = BigInteger.ONE;
for (int i = 0; i < cipherText.length; ++i) {
mul = mul.multiply(cipherText[i]);
}
return mul;
}
示例15: BlindingParameters
BlindingParameters(BigInteger e, BigInteger d, BigInteger n) {
this.u = null;
this.v = null;
this.e = e;
this.d = d;
int len = n.bitLength();
SecureRandom random = JCAUtil.getSecureRandom();
u = new BigInteger(len, random).mod(n);
// Although the possibility is very much limited that u is zero
// or is not relatively prime to n, we still want to be careful
// about the special value.
//
// Secure random generation is expensive, try to use BigInteger.ONE
// this time if this new generated random number is zero or is not
// relatively prime to n. Next time, new generated secure random
// number will be used instead.
if (u.equals(BigInteger.ZERO)) {
u = BigInteger.ONE; // use 1 this time
}
try {
// The call to BigInteger.modInverse() checks that u is
// relatively prime to n. Otherwise, ArithmeticException is
// thrown.
v = u.modInverse(n);
} catch (ArithmeticException ae) {
// if u is not relatively prime to n, use 1 this time
u = BigInteger.ONE;
v = BigInteger.ONE;
}
if (e != null) {
u = u.modPow(e, n); // e: the public exponent
// u: random ^ e
// v: random ^ (-1)
} else {
v = v.modPow(d, n); // d: the private exponent
// u: random
// v: random ^ (-d)
}
}