Package java.math

Examples of java.math.BigInteger.mod()


  private static String convertWordNumber(String number) {
    ArrayList<Character> word = new ArrayList<Character>();
    BigInteger n = new BigInteger(number);
    while (!n.equals(BigInteger.ZERO)) {
      n = n.add(BigInteger.valueOf(-1));
      int r = n.mod(BigInteger.valueOf(26)).intValue();
      word.add((char)('a' + r));
      n = n.divide(BigInteger.valueOf(26));
    }
    Collections.reverse(word);
   
View Full Code Here


        final BigInteger uvp = BigInteger.valueOf(numerator).multiply(BigInteger.valueOf(fraction.denominator / d1));
        final BigInteger upv = BigInteger.valueOf(fraction.numerator).multiply(BigInteger.valueOf(denominator / d1));
        final BigInteger t = isAdd ? uvp.add(upv) : uvp.subtract(upv);
        // but d2 doesn't need extra precision because
        // d2 = gcd(t,d1) = gcd(t mod d1, d1)
        final int tmodd1 = t.mod(BigInteger.valueOf(d1)).intValue();
        final int d2 = tmodd1 == 0 ? d1 : greatestCommonDivisor(tmodd1, d1);

        // result is (t/d2) / (u'/d1)(v'/d2)
        final BigInteger w = t.divide(BigInteger.valueOf(d2));
        if (w.bitLength() > 31) {
View Full Code Here

        result.append("}");

        // Write R^2 as little endian array of integers.
        result.append(",{");
        for (int i = 0; i < nwords; ++i) {
            long rr = RR.mod(B).longValue();
            result.append(rr);

            if (i != nwords - 1) {
                result.append(",");
            }
View Full Code Here

    public static int calc(int x, int y) {
        BigInteger bi = BigInteger.valueOf(1);
        for (int i = x; i <= y; i ++) {
            bi = bi.multiply(BigInteger.valueOf(i));
        }
        while (bi.mod(BigInteger.valueOf(10)).equals(BigInteger.valueOf(0)))
            bi = bi.divide(BigInteger.valueOf(10));

        return bi.mod(BigInteger.valueOf(10)).intValue();
    }
View Full Code Here

            bi = bi.multiply(BigInteger.valueOf(i));
        }
        while (bi.mod(BigInteger.valueOf(10)).equals(BigInteger.valueOf(0)))
            bi = bi.divide(BigInteger.valueOf(10));

        return bi.mod(BigInteger.valueOf(10)).intValue();
    }

    public static void main(String args[]) {
        for (int i = 1; i <= 100; i ++) {
            System.out.print(calc(1, i) + " ");
View Full Code Here

    BigInteger unblind(BigInteger biSignedCoin,PublicBank bank) {
  BigInteger z=bank.getPublicKey().modPow(m_biBlindingFactor,
            bank.getPrime());
  z=z.modInverse(bank.getPrime());
  z=z.multiply(biSignedCoin);
  z=z.mod(bank.getPrime());

  return z;
    }
    Coin processResponse(PublicBank bank,
       BigInteger biSignedCoinRequest) {
View Full Code Here

    BigInteger unblind(BigInteger biSignedCoin,PublicBank bank) {
  BigInteger z=bank.getPublicKey().modPow(m_biBlindingFactorG,
            bank.getPrime());
  z=z.modInverse(bank.getPrime());
  z=z.multiply(biSignedCoin);
  z=z.mod(bank.getPrime());

  BigInteger p1=bank.getPrime().subtract(Util.ONE);
  BigInteger byinv=m_biBlindingFactorY.modInverse(p1);
  z=z.modPow(byinv,bank.getPrime());
View Full Code Here

     * Accepts a byte array key and a total number of shards and returns the appropriate shard for
     * the supplied key.
     */
    public static int keyShard(byte[] key, int numShards) {
        BigInteger hash = new BigInteger(md5Hash(key));
        return hash.mod(new BigInteger("" + numShards)).intValue();
    }

    public static String convertStreamToString(InputStream is) throws IOException {
        StringBuilder sb = new StringBuilder();
        String line;
View Full Code Here

             * only need insertion order, and a plain ArrayList guarantees that.
             */
            final List<BigInteger> failed = Lists.newArrayList();

            for (final BigInteger divisor: divisors)
                if (!value.mod(divisor).equals(BigInteger.ZERO))
                    failed.add(divisor);

            if (failed.isEmpty())
                return;

View Full Code Here

             * only need insertion order, and a plain ArrayList guarantees that.
             */
            final List<BigInteger> failed = Lists.newArrayList();

            for (final BigInteger divisor: divisors)
                if (!value.mod(divisor).equals(BigInteger.ZERO))
                    failed.add(divisor);

            if (failed.isEmpty())
                return;

View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.