本文整理汇总了Java中java.math.BigInteger类的典型用法代码示例。如果您正苦于以下问题:Java BigInteger类的具体用法?Java BigInteger怎么用?Java BigInteger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BigInteger类属于java.math包,在下文中一共展示了BigInteger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sm2Verify
import java.math.BigInteger; //导入依赖的package包/类
public void sm2Verify(byte md[], ECPoint userKey, BigInteger r, BigInteger s, SM2Result sm2Result) {
sm2Result.R = null;
BigInteger e = new BigInteger(1, md);
BigInteger t = r.add(s).mod(ecc_n);
if (t.equals(BigInteger.ZERO)) {
return;
} else {
ECPoint x1y1 = ecc_point_g.multiply(sm2Result.s);
System.out.println("X0: " + x1y1.getX().toBigInteger().toString(16));
System.out.println("Y0: " + x1y1.getY().toBigInteger().toString(16));
System.out.println("");
x1y1 = x1y1.add(userKey.multiply(t));
System.out.println("X1: " + x1y1.getX().toBigInteger().toString(16));
System.out.println("Y1: " + x1y1.getY().toBigInteger().toString(16));
System.out.println("");
sm2Result.R = e.add(x1y1.getX().toBigInteger()).mod(ecc_n);
System.out.println("R: " + sm2Result.R.toString(16));
return;
}
}
示例2: get
import java.math.BigInteger; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry) {
if (clazz == BigDecimal.class) {
return (Codec<T>) bigDecimalCodec;
}
if (clazz == BigInteger.class) {
return (Codec<T>) bigIntegerCodec;
}
if (clazz == InetAddress.class || clazz == Inet4Address.class || clazz == Inet6Address.class) {
return (Codec<T>) inetAddressCodec;
}
if (clazz.isArray()) {
return (Codec<T>) arrayCodec;
}
return null;
}
示例3: getStorageAt
import java.math.BigInteger; //导入依赖的package包/类
/**
* Experimental. Returns the value from a storage position at a given address
* @param address Address
* @param position Storage position
* @return Value from storage position
*/
public String getStorageAt(String address, BigInteger position) {
HttpGet get = new HttpGet(PUBLIC_URL + "?module=proxy&action=eth_getStorageAt&address=" + address + "&position=" + "0x" + position.toString(16) + "&tag=latest" + "&apikey=" + API_KEY);
String response = null;
try(CloseableHttpResponse httpResponse = httpClient.execute(get)) {
HttpEntity httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
EntityUtils.consume(httpEntity);
} catch (IOException e) {
e.printStackTrace();
}
@SuppressWarnings("rawtypes")
ArrayList<CustomNameValuePair<String, CustomNameValuePair>> a = Utility.evaluateExpression(response);
for(int j = 0; j < a.size(); j++)
if(a.get(j).getName().toString().equals("result"))
return a.get(j).getValue().toString();
return null; // Null should not be expected when API is functional
}
示例4: parsePrivateKey
import java.math.BigInteger; //导入依赖的package包/类
@Override
public PrivateKey parsePrivateKey(byte[] encodedKey)
throws GeneralSecurityException {
long now = System.currentTimeMillis();
if (encodedKey.length != privateKeyBytes)
throw new GeneralSecurityException();
BigInteger d = new BigInteger(1, encodedKey); // Positive signum
// Verify that the private value is < n
if (d.compareTo(params.getN()) >= 0)
throw new GeneralSecurityException();
// Construct a private key from the private value and the params
ECPrivateKeyParameters k = new ECPrivateKeyParameters(d, params);
PrivateKey p = new Sec1PrivateKey(k, keyBits);
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Parsing private key took " + duration + " ms");
return p;
}
示例5: calculateE
import java.math.BigInteger; //导入依赖的package包/类
private BigInteger calculateE(BigInteger n, byte[] message)
{
if (n.bitLength() >= message.length * 8)
{
return new BigInteger(1, message);
}
else
{
byte[] trunc = new byte[n.bitLength() / 8];
System.arraycopy(message, 0, trunc, 0, trunc.length);
return new BigInteger(1, trunc);
}
}
示例6: testItem_0798
import java.math.BigInteger; //导入依赖的package包/类
public void testItem_0798()
{
boolean caught;
caught = false;
try {
rc_BigDecimal = new BigDecimal(new java.math.BigInteger("32"), 0, new MathContext("precision=1 roundingMode=UNNECESSARY"));
}
catch (java.lang.ArithmeticException e) {
caught = true;
}
Assert.assertEquals("91.94630872483222%", true, caught);
}
示例7: ByzantiumConfig
import java.math.BigInteger; //导入依赖的package包/类
public ByzantiumConfig(BlockchainConfig parent) {
super(parent);
constants = new ConstantsAdapter(super.getConstants()) {
private final BigInteger BLOCK_REWARD = new BigInteger("3000000000000000000");
@Override
public BigInteger getBLOCK_REWARD() {
return BLOCK_REWARD;
}
};
}
示例8: testDivNonZeroExact
import java.math.BigInteger; //导入依赖的package包/类
@GwtIncompatible // TODO
@AndroidIncompatible // slow
public void testDivNonZeroExact() {
boolean isAndroid = System.getProperties().getProperty("java.runtime.name").contains("Android");
for (BigInteger p : NONZERO_BIGINTEGER_CANDIDATES) {
for (BigInteger q : NONZERO_BIGINTEGER_CANDIDATES) {
if (isAndroid && p.equals(BAD_FOR_ANDROID_P) && q.equals(BAD_FOR_ANDROID_Q)) {
// https://code.google.com/p/android/issues/detail?id=196555
continue;
}
if (isAndroid && p.equals(BAD_FOR_GINGERBREAD_P) && q.equals(BAD_FOR_GINGERBREAD_Q)) {
// Works fine under Marshmallow, so I haven't filed a bug.
continue;
}
boolean dividesEvenly = p.remainder(q).equals(ZERO);
try {
BigInteger quotient = BigIntegerMath.divide(p, q, UNNECESSARY);
BigInteger undone = quotient.multiply(q);
if (!p.equals(undone)) {
failFormat("expected %s.multiply(%s) = %s; got %s", quotient, q, p, undone);
}
assertTrue(dividesEvenly);
} catch (ArithmeticException e) {
assertFalse(dividesEvenly);
}
}
}
}
示例9: mineLight
import java.math.BigInteger; //导入依赖的package包/类
/**
* This the slower miner version which uses only cache thus taking much less memory than
* regular {@link #mine} method
*/
public long mineLight(long fullSize, final byte[][] cache, byte[] blockHeaderTruncHash, long difficulty) {
BigInteger target = valueOf(2).pow(256).divide(valueOf(difficulty));
long nonce = new Random().nextLong();
while(!Thread.currentThread().isInterrupted()) {
nonce++;
Pair<byte[], byte[]> pair = hashimotoLight(fullSize, cache, blockHeaderTruncHash, longToBytes(nonce));
BigInteger h = new BigInteger(1, pair.getRight() /* ?? */);
if (h.compareTo(target) < 0) break;
}
return nonce;
}
示例10: generateRSAKeypair0
import java.math.BigInteger; //导入依赖的package包/类
@Override
protected P11Identity generateRSAKeypair0(int keysize, BigInteger publicExponent,
String label, P11NewKeyControl control) throws P11TokenException {
KeyPair keypair;
try {
keypair = KeyUtil.generateRSAKeypair(keysize, publicExponent, random);
} catch (NoSuchAlgorithmException | NoSuchProviderException
| InvalidAlgorithmParameterException ex) {
throw new P11TokenException(ex.getMessage(), ex);
}
return saveP11Entity(keypair, label);
}
示例11: main
import java.math.BigInteger; //导入依赖的package包/类
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
/*
Plot Pascal triangle of given size
*/
// take the size of the triangle (max 100)
int triangleSize = Integer.parseInt(input.nextLine());
// Make jagged array for the triangle of type BigInteger
BigInteger[][] pascTriangle = new BigInteger[triangleSize][];
// Create the first element of the triangle
pascTriangle[0] = new BigInteger[] {BigInteger.ONE};
for (int row = 1; row < triangleSize; row++) {
// create next row with length +1
pascTriangle[row] = new BigInteger[row + 1];
// for current row create first element = 1
pascTriangle[row][0] = BigInteger.ONE;
// find the middle of the row
int middle = (pascTriangle[row].length - 1) /2;
// loop to the end of the current row
for (int col = 1; col < pascTriangle[row].length; col++) {
// if the index is less or equal to the middle index
if (col <= middle){
// sum the above row members and save result at current possition
pascTriangle[row][col] = (pascTriangle[row - 1][col - 1]).add(pascTriangle[row - 1][col]);
} else {
// else, copy forward previous members
// "row - col" is in fact "(length - 1) - col" or "(last index) - current iteration"
pascTriangle[row][col] = pascTriangle[row][row - col];
}
}
}
// print the triangle
for (int row = 0; row < pascTriangle.length; row++) {
for (int col = 0; col < pascTriangle[row].length; col++) {
System.out.print(pascTriangle[row][col] + " ");
}
System.out.println();
}
}
示例12: getMD5
import java.math.BigInteger; //导入依赖的package包/类
public static String getMD5(String val) throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest digest = MessageDigest.getInstance("MD5");
digest.update(val.getBytes("UTF-8"));
byte[] magnitude = digest.digest();
BigInteger bi = new BigInteger(1, magnitude);
return String.format("%0" + (magnitude.length << 1) + "x", bi);
}
示例13: toBigNumbers
import java.math.BigInteger; //导入依赖的package包/类
@Test
public void toBigNumbers() throws IOException {
final VPackBuilder builder = new VPackBuilder();
{
builder.add(ValueType.OBJECT);
builder.add("bi", BigInteger.valueOf(2));
builder.add("bd", BigDecimal.valueOf(3.75));
builder.close();
}
final VPackSlice vpack = builder.slice();
final TestEntityBigNumber entity = mapper.readValue(vpack.getBuffer(), TestEntityBigNumber.class);
assertThat(entity, is(notNullValue()));
assertThat(entity.bi, is(BigInteger.valueOf(2)));
assertThat(entity.bd, is(BigDecimal.valueOf(3.75)));
}
示例14: execute
import java.math.BigInteger; //导入依赖的package包/类
@Override
public Pair<Boolean, byte[]> execute(byte[] data) {
if (data == null)
return Pair.of(true, EMPTY_BYTE_ARRAY);
int baseLen = parseLen(data, 0);
int expLen = parseLen(data, 1);
int modLen = parseLen(data, 2);
BigInteger base = parseArg(data, ARGS_OFFSET, baseLen);
BigInteger exp = parseArg(data, addSafely(ARGS_OFFSET, baseLen), expLen);
BigInteger mod = parseArg(data, addSafely(addSafely(ARGS_OFFSET, baseLen), expLen), modLen);
// check if modulus is zero
if (isZero(mod))
return Pair.of(true, EMPTY_BYTE_ARRAY);
byte[] res = stripLeadingZeroes(base.modPow(exp, mod).toByteArray());
// adjust result to the same length as the modulus has
if (res.length < modLen) {
byte[] adjRes = new byte[modLen];
System.arraycopy(res, 0, adjRes, modLen - res.length, res.length);
return Pair.of(true, adjRes);
} else {
return Pair.of(true, res);
}
}
示例15: decodeBigInteger
import java.math.BigInteger; //导入依赖的package包/类
public static BigInteger decodeBigInteger(byte[] data, int index) {
final int length = calculateLength(data, index);
byte[] valueBytes = new byte[length];
System.arraycopy(data, index, valueBytes, 0, length);
return new BigInteger(1, valueBytes);
}