本文整理了Java中java.math.BigInteger.<init>()
方法的一些代码示例,展示了BigInteger.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.<init>()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:<init>
[英]Constructs a random BigInteger instance in the range [0, which is probably prime. The probability that the returned BigInteger is prime is greater than 1 - 1/2certainty).
Note: the Random argument is ignored if bitLength >= 16, where this implementation will use OpenSSL's BN_generate_prime_ex as a source of cryptographically strong pseudo-random numbers.
[中]在[0]范围内构造一个随机BigInteger实例,该范围可能为素数。返回的BigInteger为素数的概率大于1-1/2确定性)。
注意:如果比特长度>=16,则忽略随机参数,其中此实现将使用OpenSSL的BN_generate_prime_ex作为加密强伪随机数的源。
代码示例来源:origin: stackoverflow.com
import java.security.SecureRandom;
import java.math.BigInteger;
public final class SessionIdentifierGenerator {
private SecureRandom random = new SecureRandom();
public String nextSessionId() {
return new BigInteger(130, random).toString(32);
}
}
代码示例来源:origin: alibaba/druid
public static BigInteger castToBigInteger(Object val) {
if (val == null) {
return null;
}
if (val instanceof BigInteger) {
return (BigInteger) val;
}
if (val instanceof String) {
return new BigInteger((String) val);
}
return BigInteger.valueOf(((Number) val).longValue());
}
代码示例来源:origin: stackoverflow.com
BigInteger reallyBig = new BigInteger("1234567890123456890");
BigInteger notSoBig = new BigInteger("2743561234");
reallyBig = reallyBig.add(notSoBig);
代码示例来源:origin: stackoverflow.com
String plaintext = "your text here";
MessageDigest m = MessageDigest.getInstance("MD5");
m.reset();
m.update(plaintext.getBytes());
byte[] digest = m.digest();
BigInteger bigInt = new BigInteger(1,digest);
String hashtext = bigInt.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
while(hashtext.length() < 32 ){
hashtext = "0"+hashtext;
}
代码示例来源:origin: stackoverflow.com
BigInteger bi = new BigInteger("76292708057987193002565060032465481997");
System.out.println(bi.toString(16));
代码示例来源:origin: stackoverflow.com
byte[] array = new BigInteger("1111000011110001", 2).toByteArray();
byte[] secondArray = new BigInteger("1111000011110001", 2).toByteArray();
if (Arrays.equals(array, secondArray))
{
System.out.println("Yup, they're the same!");
}
代码示例来源:origin: stackoverflow.com
return canonical(new BigInteger("" + numerator), new BigInteger("" + denominator), true);
return canonical(new BigInteger(numerator), new BigInteger(denominator), true);
n += decimal;
BigInteger numerator = new BigInteger(n);
denominator = BigInteger.TEN.pow(-exp);
} else {
numerator = numerator.multiply(BigInteger.TEN.pow(exp));
denominator = BigInteger.ONE;
} else {
BigInteger i1 = numerator.multiply(o.denominator);
BigInteger i2 = o.numerator.multiply(denominator);
return i1.compareTo(i2); // expensive!
return isInteger() ? new BigDecimal(numerator) : new BigDecimal(numerator).divide(new BigDecimal(denominator), scale, roundingMode);
System.out.printf("%s.floatValue() = %,f%n", name, r.floatValue());
System.out.printf("%s.doubleValue() = %,f%n", name, r.doubleValue());
System.out.println();
代码示例来源:origin: spotbugs/spotbugs
@NoWarning("FS")
public void valuesOtherThanInt() {
System.out.println(String.format("%d%n%d", 42, (short) 42));
System.out.println(String.format("%d%n", new BigInteger("42")));
System.out.println(String.format("%f%n", new BigDecimal(42)));
}
}
代码示例来源:origin: spotbugs/spotbugs
@ExpectWarning("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
void y() {
BigInteger i = BigInteger.ZERO;
if (i == null) {
i = BigInteger.ONE;
} else {
i = BigInteger.TEN;
}
System.out.println(new BigInteger("1").add(i));
}
}
代码示例来源:origin: prestodb/presto
public static Optional<BigDecimal> fromMetastoreDecimal(@Nullable Decimal decimal)
{
if (decimal == null) {
return Optional.empty();
}
return Optional.of(new BigDecimal(new BigInteger(decimal.getUnscaled()), decimal.getScale()));
}
代码示例来源:origin: web3j/web3j
BigInteger i = BigInteger.valueOf((long) recId / 2);
BigInteger x = sig.r.add(i.multiply(n));
BigInteger e = new BigInteger(1, message);
BigInteger srInv = rInv.multiply(sig.s).mod(n);
BigInteger eInvrInv = rInv.multiply(eInv).mod(n);
ECPoint q = ECAlgorithms.sumOfTwoMultiplies(CURVE.getG(), eInvrInv, R, srInv);
return new BigInteger(1, Arrays.copyOfRange(qBytes, 1, qBytes.length));
代码示例来源:origin: robovm/robovm
digestBI = new BigInteger(1, msgDigest.digest());
k = new BigInteger(1, randomBytes);
if (k.compareTo(q) != -1) {
continue;
s = k.modInverse(q).multiply(digestBI.add(x.multiply(r)).mod(q))
.mod(q);
代码示例来源:origin: immutables/immutables
@Test
public void write() throws Exception {
JsonObject obj = new JsonObject();
BigInteger bigInteger = new BigInteger(Long.toString(Long.MAX_VALUE)).multiply(new BigInteger("128"));
obj.addProperty("bigInteger", bigInteger);
BigDecimal bigDecimal = new BigDecimal(Long.MAX_VALUE).multiply(new BigDecimal(1024));
obj.addProperty("bigDecimal", bigDecimal);
BsonDocument doc = Jsons.toBson(obj);
check(doc.get("bigInteger").getBsonType()).is(BsonType.DECIMAL128);
check(doc.get("bigInteger").asDecimal128().decimal128Value().bigDecimalValue().toBigInteger()).is(bigInteger);
check(doc.get("bigDecimal").getBsonType()).is(BsonType.DECIMAL128);
check(doc.get("bigDecimal").asDecimal128().decimal128Value().bigDecimalValue()).is(bigDecimal);
}
代码示例来源:origin: apache/storm
public void execute(Tuple input, BasicOutputCollector collector) {
total = total.add(new BigInteger(input.getValues().get(1).toString()));
collector.emit(tuple(total.toString()));
//prints the total with low probability.
if(RANDOM.nextInt(1000) > 995) {
LOG.info("Running total = " + total);
}
}
代码示例来源:origin: prestodb/presto
@Test
public void testGetRingFraction()
{
assertEquals(tokenRing.getTokenCountInRange("0", "1"), ONE);
assertEquals(tokenRing.getTokenCountInRange("0", "200"), new BigInteger("200"));
assertEquals(tokenRing.getTokenCountInRange("0", "10"), new BigInteger("10"));
assertEquals(tokenRing.getTokenCountInRange("1", "11"), new BigInteger("10"));
assertEquals(tokenRing.getTokenCountInRange("0", "0"), ZERO);
assertEquals(tokenRing.getTokenCountInRange("-1", "-1"), BigInteger.valueOf(2).pow(127).add(ONE));
assertEquals(tokenRing.getTokenCountInRange("1", "0"), BigInteger.valueOf(2).pow(127));
}
代码示例来源:origin: SeanDragon/protools
/**
* 判断生成的公钥是否合法
*
* @param publicKey
* @return
*/
private boolean checkPublicKey(ECPoint publicKey) {
if (!publicKey.isInfinity()) {
BigInteger x = publicKey.getXCoord().toBigInteger();
BigInteger y = publicKey.getYCoord().toBigInteger();
if (between(x, new BigInteger("0"), p) && between(y, new BigInteger("0"), p)) {
BigInteger xResult = x.pow(3).add(a.multiply(x)).add(b).mod(p);
BigInteger yResult = y.pow(2).mod(p);
return yResult.equals(xResult) && publicKey.multiply(n).isInfinity();
}
}
return false;
}
代码示例来源:origin: Curzibn/Luban
@Override
public String rename(String filePath) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(filePath.getBytes());
return new BigInteger(1, md.digest()).toString(32);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
})
代码示例来源:origin: aa112901/remusic
public static void main3(String[] args) {
String key = "7b104953fb112826";
String pubKey = "010001";
String m = "157794750267131502212476817800345498121872783333389747424011531025366277535262539913701806290766479189477533597854989606803194253978660329941980786072432806427833685472618792592200595694346872951301770580765135349259590167490536138082469680638514416594216629258349130257685001248172188325316586707301643237607";
try {
String k = reverse(key);
String keyTo16 = toHex(k, "GBK");
// System.out.println(new BigInteger(keyTo16, 16));
// new BigInteger(keyTo16, 16) 字符串转为16进制数字,
// pow(Integer.valueOf(pubKey, 16)) 得到次方的值
//remainder 取余数
String c = (new BigInteger(keyTo16, 16).pow(Integer.valueOf(pubKey, 16))).remainder(new BigInteger(m)) + "";
//转为16进制表示
System.out.println(new BigInteger(c).toString(16));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
代码示例来源:origin: stackoverflow.com
import java.math.*;
public class Test {
public static void main(String[] args) {
String hexStr = "1b0ee1e3";
BigInteger bigInt = new BigInteger(hexStr, 16);
System.out.println(bigInt); // Prints 453960163
}
}
代码示例来源:origin: stackoverflow.com
BigInteger bi1 = new BigInteger("637824629384623845238423545642384");
BigInteger bi2 = new BigInteger("3039768898793547264523745379249934");
BigInteger bigSum = bi1.add(bi2);
BigInteger bigProduct = bi1.multiply(bi2);
System.out.println("Sum : " + bigSum);
System.out.println("Product : " + bigProduct);
内容来源于网络,如有侵权,请联系作者删除!