当前位置: 首页>>代码示例>>Java>>正文


Java BigInteger.multiply方法代码示例

本文整理汇总了Java中java.math.BigInteger.multiply方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.multiply方法的具体用法?Java BigInteger.multiply怎么用?Java BigInteger.multiply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.math.BigInteger的用法示例。


在下文中一共展示了BigInteger.multiply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mul_A_by_B

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public void mul_A_by_B( AT_Machine_State state ) {
	BigInteger a = AT_API_Helper.getBigInteger(state.get_A1(), state.get_A2(), state.get_A3(), state.get_A4());
	BigInteger b = AT_API_Helper.getBigInteger(state.get_B1(), state.get_B2(), state.get_B3(), state.get_B4());
	BigInteger result = a.multiply(b);
	ByteBuffer resultBuffer = ByteBuffer.wrap(AT_API_Helper.getByteArray(result));
	resultBuffer.order(ByteOrder.LITTLE_ENDIAN);
	
	byte[] temp = new byte[8];
	resultBuffer.get(temp, 0, 8);
	state.set_B1(temp);
	resultBuffer.get(temp, 0, 8);
	state.set_B2(temp);
	resultBuffer.get(temp, 0, 8);
	state.set_B3(temp);
	resultBuffer.get(temp, 0, 8);
	state.set_B4(temp);
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:19,代码来源:AT_API_Impl.java

示例2: main

import java.math.BigInteger; //导入方法依赖的package包/类
public static void main(String[] args) {
    String k;
    int i, n;
    BigInteger[] a = new BigInteger[1801];
    Scanner in = new Scanner(System.in);
    n = in.nextInt();
    k = in.next();
    BigInteger e = new BigInteger(k);
    BigInteger f1 = new BigInteger(String.valueOf(1));
    a[0] = e.subtract(f1);
    a[1] = e.multiply(a[0]);
    for (i = 2; i < n; i++) {
        a[i] = (a[i - 1].add(a[i - 2])).multiply(e.subtract(f1));
    }
    System.out.print(a[((n - 1))]);
}
 
开发者ID:bakhodirsbox,项目名称:AlgoCS,代码行数:17,代码来源:KbasedNum2_1012.java

示例3: pow

import java.math.BigInteger; //导入方法依赖的package包/类
public static BigInteger pow(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;
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:21,代码来源:DataWordTest.java

示例4: visitArithmeticBinary

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger visitArithmeticBinary(ArithmeticBinaryContext ctx)
{
    BigInteger left = visit(ctx.left);
    BigInteger right = visit(ctx.right);
    switch (ctx.operator.getType()) {
        case PLUS:
            return left.add(right);
        case MINUS:
            return left.subtract(right);
        case ASTERISK:
            return left.multiply(right);
        case SLASH:
            return left.divide(right);
        default:
            throw new IllegalStateException("Unsupported binary operator " + ctx.operator.getText());
    }
}
 
开发者ID:dbiir,项目名称:rainbow,代码行数:19,代码来源:TypeCalculation.java

示例5: engineDigest

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
protected void engineDigest(byte[]... elements) throws AccumulatorException {
    do {
        startValue = new BigInteger(publicParm.bitLength(), random);
    } while (startValue.compareTo(publicParm) == 1 || !startValue.gcd(publicParm).equals(BigInteger.ONE));

    BigInteger exponent = BigInteger.ONE;

    for (byte[] element : elements) {
        try {
            exponent = exponent.multiply(fullDomainHash(publicParm, element));
        } catch (NoSuchAlgorithmException e) {
            throw new AccumulatorException(e);
        }
    }

    accumulatorValue = startValue.modPow(exponent, publicParm);
    this.elements = elements;
}
 
开发者ID:woefe,项目名称:xmlrss,代码行数:20,代码来源:BPAccumulator.java

示例6: main

import java.math.BigInteger; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

		TestJCAProvider d = new TestJCAProvider();
		// Add dynamically the desired provider
		Security.addProvider(new PaillierProvider());
		
		/////////////////////////////////////////////////////////////////////
		KeyPairGenerator kpg = KeyPairGenerator.getInstance("Paillier");
		kpg.initialize(32);
		KeyPair keyPair = kpg.generateKeyPair();
		PublicKey pubKey = keyPair.getPublic();
		PrivateKey privKey = keyPair.getPrivate();
		final Cipher cipher = Cipher.getInstance("Paillier");
		final Cipher cipherHP = Cipher.getInstance("PaillierHP");
		System.out.println("The Paillier public key through Generator is \n"+keyPair.toString());
		System.out.println("The Paillier public key is \n"+keyPair.getPublic().toString());
		System.out.println("The Paillier private key is \n"+keyPair.getPrivate().toString());
		String plainText = "101";
		String plaintext1 = "101";
		// get the n
		String delims = "[,]";
		String[] keyComponents = pubKey.toString().split(delims);
		String keyComponent = "";
		for (String keyComponent2 : keyComponents) {
			if (keyComponent2.startsWith("n")) {
				keyComponent = keyComponent2.substring(2);// ignoring 'n:' or 'r:'
			}
		}
		BigInteger n = new BigInteger(keyComponent);
		BigInteger first = new BigInteger(plainText);
		BigInteger second = new BigInteger(plaintext1);
		BigInteger n2 = n.multiply(n);

		// encrypt
		BigInteger codedBytes = d.encrypt(first.toByteArray(), pubKey,cipherHP);
		BigInteger codedBytes12 = d.encrypt(second.toByteArray(), pubKey,cipherHP);
		//product
		BigInteger product = codedBytes.multiply(codedBytes12);

		// product mod n^2
		BigInteger tallyProduct = product.mod(n2);
	    System.out.println(" Product mod n^2:      "+tallyProduct);
	    d.decrypt(tallyProduct.toByteArray(), privKey,cipherHP);

		d.decrypt(codedBytes.toByteArray(),privKey,cipherHP);
		d.decrypt(codedBytes12.toByteArray(),privKey,cipherHP);
		
		//////////////////////////////BLOCK EXAMPLE/////////////////////////////////
		String plainTextBlock = "This Provider working correctly and its safe 10000000000000000011000000000000000001";
		System.out.println("This is the message which will be encrypted: " + plainTextBlock);
		
		// encrypt
		byte[] codedBytesBlock = d.encryptBlock(plainTextBlock.getBytes(), pubKey,cipher);
		String codedMessageBlock = new String(codedBytesBlock);
		String codedMessageBlockInHEX = formatingHexRepresentation(codedBytesBlock);
		System.out.println("\n" + "ENCRYPTED :  \n" + codedMessageBlock);
		System.out.println("\n" + "ENCRYPTED in HEX:  \n" + codedMessageBlockInHEX);

		// decrypt
		byte[] encodedBytesBlock = d.decryptBlock(codedMessageBlock, privKey,cipher);
		String encodedMessageBlock = new String(encodedBytesBlock);
		System.out.println("\n" + "DECRYPTED:  \n" + encodedMessageBlock);
			
		}
 
开发者ID:peterstefanov,项目名称:paillier,代码行数:65,代码来源:TestJCAProvider.java

示例7: pow

import java.math.BigInteger; //导入方法依赖的package包/类
public static void pow(int order) {
    int failCount1 = 0;

    for (int i=0; i<SIZE; i++) {
        // Test identity x^power == x*x*x ... *x
        int power = random.nextInt(6) + 2;
        BigInteger x = fetchNumber(order);
        BigInteger y = x.pow(power);
        BigInteger z = x;

        for (int j=1; j<power; j++)
            z = z.multiply(x);

        if (!y.equals(z))
            failCount1++;
    }
    report("pow for " + order + " bits", failCount1);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:BigIntegerTest.java

示例8: approximateDivisionByN

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Approximate division by <code>n</code>. For an integer
 * <code>k</code>, the value <code>&lambda; = s k / n</code> is
 * computed to <code>c</code> bits of accuracy.
 * @param k The parameter <code>k</code>.
 * @param s The curve parameter <code>s<sub>0</sub></code> or
 * <code>s<sub>1</sub></code>.
 * @param vm The Lucas Sequence element <code>V<sub>m</sub></code>.
 * @param a The parameter <code>a</code> of the elliptic curve.
 * @param m The bit length of the finite field
 * <code><b>F</b><sub>m</sub></code>.
 * @param c The number of bits of accuracy, i.e. the scale of the returned
 * <code>SimpleBigDecimal</code>.
 * @return The value <code>&lambda; = s k / n</code> computed to
 * <code>c</code> bits of accuracy.
 */
public static SimpleBigDecimal approximateDivisionByN(BigInteger k,
        BigInteger s, BigInteger vm, byte a, int m, int c)
{
    int _k = (m + 5)/2 + c;
    BigInteger ns = k.shiftRight(m - _k - 2 + a);

    BigInteger gs = s.multiply(ns);

    BigInteger hs = gs.shiftRight(m);

    BigInteger js = vm.multiply(hs);

    BigInteger gsPlusJs = gs.add(js);
    BigInteger ls = gsPlusJs.shiftRight(_k-c);
    if (gsPlusJs.testBit(_k-c-1))
    {
        // round up
        ls = ls.add(ECConstants.ONE);
    }

    return new SimpleBigDecimal(ls, c);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:39,代码来源:Tnaf.java

示例9: chineseRemainder

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Computes the integer x that is expressed through the given primes and the
 * congruences with the chinese remainder theorem (CRT).
 * 
 * @param congruences
 *            the congruences c_i
 * @param primes
 *            the primes p_i
 * @return an integer x for that x % p_i == c_i
 */
private static BigInteger chineseRemainder(Vector congruences, Vector primes)
{
    BigInteger retval = ZERO;
    BigInteger all = ONE;
    for (int i = 0; i < primes.size(); i++)
    {
        all = all.multiply((BigInteger)primes.elementAt(i));
    }
    for (int i = 0; i < primes.size(); i++)
    {
        BigInteger a = (BigInteger)primes.elementAt(i);
        BigInteger b = all.divide(a);
        BigInteger b_ = b.modInverse(a);
        BigInteger tmp = b.multiply(b_);
        tmp = tmp.multiply((BigInteger)congruences.elementAt(i));
        retval = retval.add(tmp);
    }

    return retval.mod(all);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:31,代码来源:NaccacheSternEngine.java

示例10: crc

import java.math.BigInteger; //导入方法依赖的package包/类
public static byte[] crc(byte[] data) {
    byte[] sum = new byte[2];
    int len = data.length;
    for (int i = 0; i + 1 < len; i = i + 2) {
        sum[0] ^= data[i + 1];
        sum[1] ^= data[i];
    }//现在数据都是偶数位
    BigInteger b = new BigInteger(1, sum);
    b = b.multiply(BigInteger.valueOf(711));
    byte[] bytes = b.toByteArray();
    len = bytes.length;
    //System.out.println(toHexString(bytes));
    byte[] ret = new byte[4];
    for (int i = 0; i < 4 && len > 0; i++) {
        ret[i] = bytes[--len];
    }
    return ret;
}
 
开发者ID:wintercoder,项目名称:Gdufe-Drcom-Android,代码行数:19,代码来源:ByteUtil.java

示例11: getTotalSent

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Returns the amount of bitcoin ever sent via output. If an output is sent to our own wallet, because of change or
 * rotating keys or whatever, we do not count it. If the wallet was
 * involved in a shared transaction, i.e. there is some input to the transaction that we don't have the key for, then
 * we multiply the sum of the output values by the proportion of satoshi coming in to our inputs. Essentially we treat
 * inputs as pooling into the transaction, becoming fungible and being equally distributed to all outputs.
 * @return the total amount of satoshis sent by us
 */
public Coin getTotalSent() {
    Coin total = Coin.ZERO;

    for (Transaction tx: transactions.values()) {
        // Count spent outputs to only if they were not to us. This means we don't count change outputs.
        Coin txOutputTotal = Coin.ZERO;
        for (TransactionOutput out : tx.getOutputs()) {
            if (out.isMine(this) == false) {
                txOutputTotal = txOutputTotal.add(out.getValue());
            }
        }

        // Count the input values to us
        Coin txOwnedInputsTotal = Coin.ZERO;
        for (TransactionInput in : tx.getInputs()) {
            TransactionOutput prevOut = in.getConnectedOutput();
            if (prevOut != null && prevOut.isMine(this)) {
                txOwnedInputsTotal = txOwnedInputsTotal.add(prevOut.getValue());
            }
        }

        // If there is an input that isn't from us, i.e. this is a shared transaction
        Coin txInputsTotal = tx.getInputSum();
        if (txOwnedInputsTotal != txInputsTotal) {

            // multiply our output total by the appropriate proportion to account for the inputs that we don't own
            BigInteger txOutputTotalNum = new BigInteger(txOutputTotal.toString());
            txOutputTotalNum = txOutputTotalNum.multiply(new BigInteger(txOwnedInputsTotal.toString()));
            txOutputTotalNum = txOutputTotalNum.divide(new BigInteger(txInputsTotal.toString()));
            txOutputTotal = Coin.valueOf(txOutputTotalNum.longValue());
        }
        total = total.add(txOutputTotal);

    }
    return total;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:45,代码来源:Wallet.java

示例12: decode

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * decodes a Base58 byte array.
 *
 * @param input
 *            the base58 string to use.
 * @return the decoded byte array.
 */
public static byte[] decode(final String input) {

	BigInteger bi = BigInteger.ZERO;

	for (int ix = 0; ix < input.length(); ix++) {
		final char c = input.charAt(ix);
		final int index = ALPHABET.indexOf(c);
		if (index == -1) {
			throw new RuntimeException("invalid char:" + c);
		}

		bi = bi.multiply(BIGINT_58);
		bi = bi.add(BigInteger.valueOf(index));
	}
	final byte[] bytes = bi.toByteArray();

	final boolean stripSignByte = (bytes.length > 1) && (bytes[0] == 0) && (bytes[1] >= (byte) 0x80);

	ArrayUtils.reverse(bytes);

	final ByteArrayOutputStream bout = new ByteArrayOutputStream();
	try {
		if (stripSignByte) {
			bout.write(bytes, 0, bytes.length - 1);
		} else {
			bout.write(bytes);
		}
		for (int ix = 0; (ix < input.length()) && (input.charAt(ix) == ALPHABET.charAt(0)); ix++) {
			bout.write(new byte[1]);
		}
	} catch (final IOException e) {
		throw new RuntimeException(e);
	}

	final byte[] ba = bout.toByteArray();
	return ba;
}
 
开发者ID:coranos,项目名称:neo-java,代码行数:45,代码来源:Base58Util.java

示例13: testBigIntegers

import java.math.BigInteger; //导入方法依赖的package包/类
public void testBigIntegers() throws IOException
{
    BigInteger bigBase = BigInteger.valueOf(Long.MAX_VALUE);
    final BigInteger[] input = new BigInteger[] {
            // Since JSON doesn't denote "real" type, just deduces from magnitude,
            // let's not test any values within int/long range
            /*
            BigInteger.ZERO,
            BigInteger.ONE,
            BigInteger.TEN,
            BigInteger.valueOf(-999L),
            bigBase,
            */
            bigBase.shiftLeft(100).add(BigInteger.valueOf(123456789L)),
            bigBase.add(bigBase),
            bigBase.multiply(BigInteger.valueOf(17)),
            bigBase.negate().subtract(BigInteger.TEN)
    };
    ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
    JsonFactory f = JSON_F;
    JsonGenerator g = f.createGenerator(ObjectWriteContext.empty(), bytes);
    g.writeStartArray();
    for (int i = 0; i < input.length; ++i) {
        g.writeNumber(input[i]);
    }
    g.writeEndArray();
    g.close();
    byte[] data = bytes.toByteArray();
    _testBigIntegers(f, input, data, 0, 100);
    _testBigIntegers(f, input, data, 0, 3);
    _testBigIntegers(f, input, data, 0, 1);

    _testBigIntegers(f, input, data, 1, 100);
    _testBigIntegers(f, input, data, 2, 3);
    _testBigIntegers(f, input, data, 3, 1);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:AsyncScalarArrayTest.java

示例14: divideLarge

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Sanity test for Burnikel-Ziegler division.  The Burnikel-Ziegler division
 * algorithm is used when each of the dividend and the divisor has at least
 * a specified number of ints in its representation.  This test is based on
 * the observation that if {@code w = u*pow(2,a)} and {@code z = v*pow(2,b)}
 * where {@code abs(u) > abs(v)} and {@code a > b && b > 0}, then if
 * {@code w/z = q1*z + r1} and {@code u/v = q2*v + r2}, then
 * {@code q1 = q2*pow(2,a-b)} and {@code r1 = r2*pow(2,b)}.  The test
 * ensures that {@code v} is just under the B-Z threshold, that {@code z} is
 * over the threshold and {@code w} is much larger than {@code z}. This
 * implies that {@code u/v} uses the standard division algorithm and
 * {@code w/z} uses the B-Z algorithm.  The results of the two algorithms
 * are then compared using the observation described in the foregoing and
 * if they are not equal a failure is logged.
 */
public static void divideLarge() {
    int failCount = 0;

    BigInteger base = BigInteger.ONE.shiftLeft(BITS_BURNIKEL_ZIEGLER + BITS_BURNIKEL_ZIEGLER_OFFSET - 33);
    for (int i=0; i<SIZE; i++) {
        BigInteger addend = new BigInteger(BITS_BURNIKEL_ZIEGLER + BITS_BURNIKEL_ZIEGLER_OFFSET - 34, rnd);
        BigInteger v = base.add(addend);

        BigInteger u = v.multiply(BigInteger.valueOf(2 + rnd.nextInt(Short.MAX_VALUE - 1)));

        if(rnd.nextBoolean()) {
            u = u.negate();
        }
        if(rnd.nextBoolean()) {
            v = v.negate();
        }

        int a = BITS_BURNIKEL_ZIEGLER_OFFSET + rnd.nextInt(16);
        int b = 1 + rnd.nextInt(16);
        BigInteger w = u.multiply(BigInteger.ONE.shiftLeft(a));
        BigInteger z = v.multiply(BigInteger.ONE.shiftLeft(b));

        BigInteger[] divideResult = u.divideAndRemainder(v);
        divideResult[0] = divideResult[0].multiply(BigInteger.ONE.shiftLeft(a - b));
        divideResult[1] = divideResult[1].multiply(BigInteger.ONE.shiftLeft(b));
        BigInteger[] bzResult = w.divideAndRemainder(z);

        if (divideResult[0].compareTo(bzResult[0]) != 0 ||
                divideResult[1].compareTo(bzResult[1]) != 0) {
            failCount++;
        }
    }

    report("divideLarge", failCount);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:51,代码来源:BigIntegerTest.java

示例15: multiply

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * D.3.2 pg 101
 * @see org.gudy.bouncycastle.math.ec.ECMultiplier#multiply(org.gudy.bouncycastle.math.ec.ECPoint, java.math.BigInteger)
 */
@Override
public ECPoint multiply(ECPoint p, BigInteger k, PreCompInfo preCompInfo)
{
    // TODO Probably should try to add this
    // BigInteger e = k.mod(n); // n == order of p
    BigInteger e = k;
    BigInteger h = e.multiply(BigInteger.valueOf(3));

    ECPoint neg = p.negate();
    ECPoint R = p;

    for (int i = h.bitLength() - 2; i > 0; --i)
    {
        R = R.twice();

        boolean hBit = h.testBit(i);
        boolean eBit = e.testBit(i);

        if (hBit != eBit)
        {
            R = R.add(hBit ? p : neg);
        }
    }

    return R;
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:31,代码来源:FpNafMultiplier.java


注:本文中的java.math.BigInteger.multiply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。