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


Java BigInteger.modPow方法代码示例

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


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

示例1: calculateZeroKnowledgeProof

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Calculate a zero knowledge proof of x using Schnorr's signature.
 * The returned array has two elements {g^v, r = v-x*h} for x.
 */
public static BigInteger[] calculateZeroKnowledgeProof(
    BigInteger p,
    BigInteger q,
    BigInteger g,
    BigInteger gx,
    BigInteger x,
    String participantId,
    Digest digest,
    SecureRandom random)
{
    BigInteger[] zeroKnowledgeProof = new BigInteger[2];

    /* Generate a random v, and compute g^v */
    BigInteger vMin = ZERO;
    BigInteger vMax = q.subtract(ONE);
    BigInteger v = BigIntegers.createRandomInRange(vMin, vMax, random);

    BigInteger gv = g.modPow(v, p);
    BigInteger h = calculateHashForZeroKnowledgeProof(g, gv, gx, participantId, digest); // h

    zeroKnowledgeProof[0] = gv;
    zeroKnowledgeProof[1] = v.subtract(x.multiply(h)).mod(q); // r = v-x*h

    return zeroKnowledgeProof;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:30,代码来源:JPAKEUtil.java

示例2: main

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

    for (int i=0; i<2000; i++) {
        BigInteger m = new BigInteger(800, rnd);
        BigInteger base = new BigInteger(16, rnd);
        if (rnd.nextInt() % 1 == 0)
            base = base.negate();
        BigInteger exp = new BigInteger(8, rnd);

        BigInteger z = base.modPow(exp, m);
        BigInteger w = base.pow(exp.intValue()).mod(m);
        if (!z.equals(w)){
            System.err.println(base +" ** " + exp + " mod "+ m);
            System.err.println("modPow : " + z);
            System.err.println("pow.mod: " + w);
            throw new RuntimeException("BigInteger modPow failure.");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ModPow.java

示例3: procedure_C

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Procedure C
 * procedure generates the a value from the given p,q,
 * returning the a value.
 */
private BigInteger procedure_C(BigInteger p, BigInteger q)
{
    BigInteger pSub1 = p.subtract(ONE);
    BigInteger pSub1DivQ = pSub1.divide(q);
    int length = p.bitLength();

    for(;;)
    {
        BigInteger d = new BigInteger(length, init_random);

        // 1 < d < p-1
        if (d.compareTo(ONE) > 0 && d.compareTo(pSub1) < 0)
        {
            BigInteger a = d.modPow(pSub1DivQ, p);

            if (a.compareTo(ONE) != 0)
            {
                return a;
            }
        }
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:28,代码来源:GOST3410ParametersGenerator.java

示例4: modExp

import java.math.BigInteger; //导入方法依赖的package包/类
public static void modExp(int order1, int order2) {
    int failCount = 0;

    for (int i=0; i<SIZE/10; i++) {
        BigInteger m = fetchNumber(order1).abs();
        while(m.compareTo(BigInteger.ONE) != 1)
            m = fetchNumber(order1).abs();
        BigInteger base = fetchNumber(order2);
        BigInteger exp = fetchNumber(8).abs();

        BigInteger z = base.modPow(exp, m);
        BigInteger w = base.pow(exp.intValue()).mod(m);
        if (!z.equals(w)) {
            System.err.println("z is "+z);
            System.err.println("w is "+w);
            System.err.println("mod is "+m);
            System.err.println("base is "+base);
            System.err.println("exp is "+exp);
            failCount++;
        }
    }
    report("Exponentiation I for " + order1 + " and " +
           order2 + " bits", failCount);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:BigIntegerTest.java

示例5: priCrypt

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * RSA non-CRT private key operations.
 */
private static byte[] priCrypt(byte[] msg, BigInteger n, BigInteger exp)
        throws BadPaddingException {

    BigInteger c = parseMsg(msg, n);
    BlindingRandomPair brp = null;
    BigInteger m;
    if (ENABLE_BLINDING) {
        brp = getBlindingRandomPair(null, exp, n);
        c = c.multiply(brp.u).mod(n);
        m = c.modPow(exp, n);
        m = m.multiply(brp.v).mod(n);
    } else {
        m = c.modPow(exp, n);
    }

    return toByteArray(m, getByteLength(n));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:RSACore.java

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

示例7: calculateA

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Calculate A as done in round 2.
 */
public static BigInteger calculateA(
    BigInteger p,
    BigInteger q,
    BigInteger gA,
    BigInteger x2s)
{
    // A = ga^(x*s)
    return gA.modPow(x2s, p);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:JPAKEUtil.java

示例8: encrypt

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Generate and encapsulate a random session key.
 *
 * @param out    the output buffer for the encapsulated key.
 * @param outOff the offset for the output buffer.
 * @param keyLen the length of the random session key.
 * @return the random session key.
 */
public CipherParameters encrypt(byte[] out, int outOff, int keyLen)
    throws IllegalArgumentException
{
    if (key.isPrivate())
    {
        throw new IllegalArgumentException("Public key required for encryption");
    }

    BigInteger n = key.getModulus();
    BigInteger e = key.getExponent();

    // Generate the ephemeral random and encode it    
    BigInteger r = BigIntegers.createRandomInRange(ZERO, n.subtract(ONE), rnd);
    byte[] R = BigIntegers.asUnsignedByteArray((n.bitLength() + 7) / 8, r);

    // Encrypt the random and encode it     
    BigInteger c = r.modPow(e, n);
    byte[] C = BigIntegers.asUnsignedByteArray((n.bitLength() + 7) / 8, c);
    System.arraycopy(C, 0, out, outOff, C.length);


    // Initialise the KDF
    kdf.init(new KDFParameters(R, null));

    // Generate the secret key
    byte[] K = new byte[keyLen];
    kdf.generateBytes(K, 0, K.length);

    return new KeyParameter(K);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:39,代码来源:RSAKeyEncapsulation.java

示例9: crypt

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * RSA public key ops. Simple modPow().
 */
private static byte[] crypt(byte[] msg, BigInteger n, BigInteger exp)
        throws BadPaddingException {
    BigInteger m = parseMsg(msg, n);
    BigInteger c = m.modPow(exp, n);
    return toByteArray(c, getByteLength(n));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:RSACore.java

示例10: calculateGenerator_FIPS186_3_Verifiable

import java.math.BigInteger; //导入方法依赖的package包/类
private static BigInteger calculateGenerator_FIPS186_3_Verifiable(Digest d, BigInteger p, BigInteger q,
        byte[] seed, int index)
    {
// A.2.3 Verifiable Canonical Generation of the Generator g
        BigInteger e = p.subtract(ONE).divide(q);
        byte[] ggen = Hex.decode("6767656E");

        // 7. U = domain_parameter_seed || "ggen" || index || count.
        byte[] U = new byte[seed.length + ggen.length + 1 + 2];
        System.arraycopy(seed, 0, U, 0, seed.length);
        System.arraycopy(ggen, 0, U, seed.length, ggen.length);
        U[U.length - 3] = (byte)index;

        byte[] w = new byte[d.getDigestSize()];
        for (int count = 1; count < (1 << 16); ++count)
        {
            inc(U);
            hash(d, U, w);
            BigInteger W = new BigInteger(1, w);
            BigInteger g = W.modPow(e, p);
            if (g.compareTo(TWO) >= 0)
            {
                return g;
            }
        }

        return null;
    }
 
开发者ID:Appdome,项目名称:ipack,代码行数:29,代码来源:DSAParametersGenerator.java

示例11: generateV

import java.math.BigInteger; //导入方法依赖的package包/类
private BigInteger generateV(BigInteger y, BigInteger p,
         BigInteger q, BigInteger g, BigInteger w, BigInteger r)
         throws SignatureException {

    byte[] s2;
    try {
        s2 = md.digest();
    } catch (RuntimeException re) {
        // Only for RawDSA due to its 20-byte length restriction
        throw new SignatureException(re.getMessage());
    }
    // get the leftmost min(N, outLen) bits of the digest value
    int nBytes = q.bitLength()/8;
    if (nBytes < s2.length) {
        s2 = Arrays.copyOfRange(s2, 0, nBytes);
    }
    BigInteger z = new BigInteger(1, s2);

    BigInteger u1 = z.multiply(w).mod(q);
    BigInteger u2 = (r.multiply(w)).mod(q);

    BigInteger t1 = g.modPow(u1,p);
    BigInteger t2 = y.modPow(u2,p);
    BigInteger t3 = t1.multiply(t2);
    BigInteger t5 = t3.mod(p);
    return t5.mod(q);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:DSA.java

示例12: main

import java.math.BigInteger; //导入方法依赖的package包/类
public static void main(String ... ags)throws IOException
{
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	int n = Integer.parseInt(in.readLine());
	BigInteger exp = new BigInteger("3");
	exp = exp.pow(n);
	BigInteger res = new BigInteger("3");
	res = res.modPow(exp,new BigInteger("1000000007"));
	System.out.println(res);
}
 
开发者ID:hell-sing,项目名称:hacker-rank,代码行数:11,代码来源:Tower_3_coloring.java

示例13: srpVerifierLowercaseV

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Calculate the SRP verifier <tt>v</tt> value.
 */
public static BigInteger srpVerifierLowercaseV(byte[] emailUTF8, byte[] srpPWBytes, byte[] srpSaltBytes, BigInteger g, BigInteger N)
    throws NoSuchAlgorithmException, UnsupportedEncodingException {
  BigInteger x = srpVerifierLowercaseX(emailUTF8, srpPWBytes, srpSaltBytes);
  BigInteger v = g.modPow(x, N);
  return v;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:10,代码来源:FxAccountUtils.java

示例14: millerRabinPrimeTest

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Miller-Rabin probabilistic primality test for int type, used in such a way that a result is always guaranteed.
 * <p/>
 * It uses the prime numbers as successive base therefore it is guaranteed to be always correct.
 * (see Handbook of applied cryptography by Menezes, table 4.1)
 *
 * @param n number to test: an odd integer &ge; 3
 * @return true if n is prime. false if n is definitely composite.
 */
public static boolean millerRabinPrimeTest(final int n) {
    final int nMinus1 = n - 1;
    final int s = Integer.numberOfTrailingZeros(nMinus1);
    final int r = nMinus1 >> s;
    //r must be odd, it is not checked here
    int t = 1;
    if (n >= 2047) {
        t = 2;
    }
    if (n >= 1373653) {
        t = 3;
    }
    if (n >= 25326001) {
        t = 4;
    } // works up to 3.2 billion, int range stops at 2.7 so we are safe :-)
    BigInteger br = BigInteger.valueOf(r);
    BigInteger bn = BigInteger.valueOf(n);

    for (int i = 0; i < t; i++) {
        BigInteger a = BigInteger.valueOf(PRIMES[i]);
        BigInteger bPow = a.modPow(br, bn);
        int y = bPow.intValue();
        if ((1 != y) && (y != nMinus1)) {
            int j = 1;
            while ((j <= s - 1) && (nMinus1 != y)) {
                long square = ((long) y) * y;
                y = (int) (square % n);
                if (1 == y) {
                    return false;
                } // definitely composite
                j++;
            }
            if (nMinus1 != y) {
                return false;
            } // definitely composite
        }
    }
    return true; // definitely prime
}
 
开发者ID:DantaFramework,项目名称:Core,代码行数:49,代码来源:NumberUtils.java

示例15: engineVerify

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
protected boolean engineVerify(byte[] witness, byte[] element) throws AccumulatorException {
    BigInteger hash;
    try {
        hash = fullDomainHash(publicKey.getKey(), element);
    } catch (NoSuchAlgorithmException e) {
        throw new AccumulatorException(e);
    }

    BigInteger proofAsInt = new BigInteger(witness);
    BigInteger acc_aux = proofAsInt.modPow(hash, publicKey.getKey());

    return Arrays.equals(acc_aux.toByteArray(), accumulatorValueRaw);
}
 
开发者ID:woefe,项目名称:xmlrss,代码行数:15,代码来源:PSAccumulator.java


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