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


Java BigInteger.divide方法代码示例

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


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

示例1: pollardRho

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Pollard's Rho cracking algorithm
 * @param pbKey Public key to crack
 * @param pbExp Public exponent of the key to crack
 */
public static void pollardRho(BigInteger pbKey, BigInteger pbExp) {

	BigInteger p;
	BigInteger x  = new BigInteger("2");
	BigInteger y = x;
	do {
		x = x.multiply(x).add(BigInteger.ONE).mod(pbKey);
		y = y.multiply(y).add(BigInteger.ONE).mod(pbKey);
		y = y.multiply(y).add(BigInteger.ONE).mod(pbKey);
		p = x.subtract(y).gcd(pbKey);
	} while (p.compareTo(BigInteger.ONE) == 0);

	if (p.compareTo(pbKey) == 0)
		return;
	BigInteger q = pbKey.divide(p);
	calcPrivateExp(p, q, pbExp);

}
 
开发者ID:cybernova,项目名称:RSAbreaker,代码行数:24,代码来源:RSAbreaker.java

示例2: init

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * This method is the core of all constructors. It takes the numerator and
 * the  denominator as BigIntegers and produces a BigRational, reducing the
 * fraction if needed.
 *
 * @param numerator The numerator of the rational number
 * @param denominator The denominator of the rational number
 * @param isNormal True if the fraction is already in reduced form, false otherwise.
 */
private void init(BigInteger numerator, BigInteger denominator, boolean isNormal) {
    // If isNormal, then we do not need to reduce the fraction and compute the gcd
    // deal with x / 0
    if (denominator.equals(BigInteger.ZERO)) {
        throw new RuntimeException("Denominator is zero");
    }

    if (!isNormal) {
        // reduce fraction
        BigInteger g = numerator.gcd(denominator);

        num = numerator.divide(g);
        den = denominator.divide(g);
    } else {
        num = numerator;
        den = denominator;
    }
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:28,代码来源:BigRational.java

示例3: toBase56

import java.math.BigInteger; //导入方法依赖的package包/类
private static String toBase56(byte[] value) {
    StringBuilder builder = new StringBuilder();
    BigInteger quotient = new BigInteger(value);

    BigInteger base = new BigInteger("56");

    int size = 0;
    while (quotient.compareTo(BigInteger.ZERO) > 0 || size < PASSWORD_SIZE) {
        int remainder = quotient.mod(base).intValue();
        builder.append(BASE56_ENCODING_CHARS.charAt(remainder));
        quotient = quotient.divide(base);
        size++;
    }

    return builder.toString();
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:17,代码来源:PasswordGenerator.java

示例4: bigIntegerReverse

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Reverses the digits of a {@link BigInteger}.
 * (123456789 --> 987654321)
 *
 * @param  n The BigInteger.
 * @param  abort An {@link AtomicBoolean} used to abort the execution
 *               for whatever reason; Can be null.
 * @throws NullPointerException if {@code n} is null.
 * @throws IllegalArgumentException if {@code n} is less than or equal to zero.
 * @return The reverse of {@code n}, {@code null} if aborted.
 */
static BigInteger bigIntegerReverse(final BigInteger n, final AtomicBoolean abort) {

    if (n == null)
        throw new NullPointerException("n value can't be null");

    if (n.compareTo(ZERO) <= 0)
        throw new IllegalArgumentException("n value must be greater than zero");

    BigInteger test = n;
    BigInteger reverse = ZERO;

    while (test.compareTo(ZERO) != 0) {
        reverse = reverse.multiply(TEN).add(test.divideAndRemainder(TEN)[1]);
        test = test.divide(TEN);

        if (abort != null && abort.get())
            return null;

    }

    return reverse;
}
 
开发者ID:MaXcRIMe,项目名称:Positive-Integers-Porperties,代码行数:34,代码来源:GenericMethods.java

示例5: bigIntSqRootFloor

import java.math.BigInteger; //导入方法依赖的package包/类
public static BigInteger bigIntSqRootFloor(BigInteger x)
        throws IllegalArgumentException {
    if (x.compareTo(BigInteger.ZERO) < 0) {
        throw new IllegalArgumentException("Negative argument.");
    }
    // square roots of 0 and 1 are trivial and
    // y == 0 will cause a divide-by-zero exception
    if (x .equals(BigInteger.ZERO) || x.equals(BigInteger.ONE)) {
        return x;
    } // end if
    BigInteger two = BigInteger.valueOf(2L);
    BigInteger y;
    // starting with y = x / 2 avoids magnitude issues with x squared
    for (y = x.divide(two);
            y.compareTo(x.divide(y)) > 0;
            y = ((x.divide(y)).add(y)).divide(two));
    return y;
}
 
开发者ID:ate47,项目名称:ATEBot,代码行数:19,代码来源:MathHelp.java

示例6: bigIntSqRootCeil

import java.math.BigInteger; //导入方法依赖的package包/类
public static BigInteger bigIntSqRootCeil(BigInteger x) throws IllegalArgumentException {
    if (x.compareTo(BigInteger.ZERO) < 0) {
        throw new IllegalArgumentException("Negative argument.");
    }
    // square roots of 0 and 1 are trivial and
    // y == 0 will cause a divide-by-zero exception
    if (x == BigInteger.ZERO || x == BigInteger.ONE) {
        return x;
    } // end if
    BigInteger two = BigInteger.valueOf(2L);
    BigInteger y;
    // starting with y = x / 2 avoids magnitude issues with x squared
    for (y = x.divide(two);
            y.compareTo(x.divide(y)) > 0;
            y = ((x.divide(y)).add(y)).divide(two));
    if (x.compareTo(y.multiply(y)) == 0) {
        return y;
    } else {
        return y.add(BigInteger.ONE);
    }
}
 
开发者ID:ate47,项目名称:ATEBot,代码行数:22,代码来源:MathHelp.java

示例7: split

import java.math.BigInteger; //导入方法依赖的package包/类
public byte[][] split(int n) {
  Preconditions.checkArgument(lastRowInt.compareTo(firstRowInt) > 0,
      "last row (%s) is configured less than first row (%s)", lastRow,
      firstRow);
  // +1 to range because the last row is inclusive
  BigInteger range = lastRowInt.subtract(firstRowInt).add(BigInteger.ONE);
  Preconditions.checkState(range.compareTo(BigInteger.valueOf(n)) >= 0,
      "split granularity (%s) is greater than the range (%s)", n, range);

  BigInteger[] splits = new BigInteger[n - 1];
  BigInteger sizeOfEachSplit = range.divide(BigInteger.valueOf(n));
  for (int i = 1; i < n; i++) {
    // NOTE: this means the last region gets all the slop.
    // This is not a big deal if we're assuming n << MAXHEX
    splits[i - 1] = firstRowInt.add(sizeOfEachSplit.multiply(BigInteger
        .valueOf(i)));
  }
  return convertToBytes(splits);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:20,代码来源:RegionSplitter.java

示例8: calcDifficulty

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent) {
    BigInteger pd = parent.getDifficultyBI();
    BigInteger quotient = pd.divide(getConstants().getDIFFICULTY_BOUND_DIVISOR());

    BigInteger sign = getCalcDifficultyMultiplier(curBlock, parent);

    BigInteger fromParent = pd.add(quotient.multiply(sign));
    BigInteger difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), fromParent);

    int explosion = getExplosion(curBlock, parent);

    if (explosion >= 0) {
        difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), difficulty.add(BigInteger.ONE.shiftLeft(explosion)));
    }

    return difficulty;
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:19,代码来源:AbstractConfig.java

示例9: 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

示例10: ModularSolverParallelTask

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Creates a ModularSolverParallelTask for solving a residual linear system.
 * @param mod The prime modulo corresponding to this system
 * @param M The product of all prime moduli
 */
public ModularSolverParallelTask(BigInteger mod, BigInteger M) {
    this.mod = mod;
    this.M = M;
    BigInteger Mi = M.divide(mod);
    factor = Mi.modInverse(mod).multiply(Mi); //<Mi(-1)>Ni (modular multiplicative inverse)
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:12,代码来源:ModularSolverParallelTask.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: revert

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger revert(BigInteger value, BigInteger constantInt) throws TraceException {
    if (constantInt.compareTo(BigInteger.valueOf(0)) == 0) {
        throw new TraceException("Cannot revert MUL if the constant is 0");
    }
    return value.divide(constantInt);
}
 
开发者ID:fergarrui,项目名称:ethereum-bytecode-analyzer,代码行数:8,代码来源:MulRevert.java

示例13: divideAndRemainder

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

    for (int i=0; i<SIZE; i++) {
        BigInteger x = fetchNumber(order).abs();
        while(x.compareTo(BigInteger.valueOf(3L)) != 1)
            x = fetchNumber(order).abs();
        BigInteger z = x.divide(BigInteger.valueOf(2L));
        BigInteger y[] = x.divideAndRemainder(x);
        if (!y[0].equals(BigInteger.ONE)) {
            failCount1++;
            System.err.println("fail1 x :"+x);
            System.err.println("      y :"+y);
        }
        else if (!y[1].equals(BigInteger.ZERO)) {
            failCount1++;
            System.err.println("fail2 x :"+x);
            System.err.println("      y :"+y);
        }

        y = x.divideAndRemainder(z);
        if (!y[0].equals(BigInteger.valueOf(2))) {
            failCount1++;
            System.err.println("fail3 x :"+x);
            System.err.println("      y :"+y);
        }
    }
    report("divideAndRemainder for " + order + " bits", failCount1);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:BigIntegerTest.java

示例14: tonellishanks

import java.math.BigInteger; //导入方法依赖的package包/类
public static BigInteger tonellishanks(BigInteger n, BigInteger p) {
    //1. By factoring out powers of 2, find Q and S such that p-1=Q2^S p-1=Q*2^S and Q is odd
    BigInteger p_1 = p.subtract(BigInteger.ONE);
    BigInteger S = BigInteger.ZERO;
    BigInteger Q = p_1;

    BigInteger two = BigInteger.valueOf(2);

    System.out.println("p         : " + Util.bytesToHex(p.toByteArray()));
    System.out.println("p is prime: " + p.isProbablePrime(10));
    System.out.println("n         : " + Util.bytesToHex(n.toByteArray()));
    System.out.println("Q         : " + Util.bytesToHex(Q.toByteArray()));
    System.out.println("S         : " + Util.bytesToHex(S.toByteArray()));

    while (Q.mod(two).compareTo(BigInteger.ONE) != 0) { //while Q is not odd
        Q = p_1.divide(two.modPow(S, p));
        S = S.add(BigInteger.ONE);

    	//System.out.println("Iter n: " + bytesToHex(n.toByteArray()));
        //System.out.println("Iter Q: " + bytesToHex(Q.toByteArray()));
        //System.out.println("Iter S: " + bytesToHex(S.toByteArray()));
    }

	//System.out.println("n: " + bytesToHex(n.toByteArray()));
    //System.out.println("Q: " + bytesToHex(Q.toByteArray()));
    //System.out.println("S: " + bytesToHex(S.toByteArray()));
    return n;
}
 
开发者ID:OpenCryptoProject,项目名称:JCMathLib,代码行数:29,代码来源:Util.java

示例15: getValueShortString

import java.math.BigInteger; //导入方法依赖的package包/类
public static String getValueShortString(BigInteger number) {
    BigInteger result = number;
    int pow = 0;
    while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) {
        result = result.divide(_1000_);
        pow += 3;
    }
    return result.toString() + "\u00b7(" + "10^" + pow + ")";
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:10,代码来源:Utils.java


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