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


Java BigInteger.testBit方法代码示例

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


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

示例1: decompressPoint

import java.math.BigInteger; //导入方法依赖的package包/类
protected ECPoint decompressPoint(int yTilde, BigInteger X1)
{
    ECFieldElement x = fromBigInteger(X1);
    ECFieldElement alpha = x.multiply(x.square().add(a)).add(b);
    ECFieldElement beta = alpha.sqrt();

    //
    // if we can't find a sqrt we haven't got a point on the
    // curve - run!
    //
    if (beta == null)
    {
        throw new RuntimeException("Invalid point compression");
    }

    BigInteger betaValue = beta.toBigInteger();
    int bit0 = betaValue.testBit(0) ? 1 : 0;

    if (bit0 != yTilde)
    {
        // Use the other root
        beta = fromBigInteger(q.subtract(betaValue));
    }

    return new ECPoint.Fp(this, x, beta, true);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:27,代码来源:ECCurve.java

示例2: multiply

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * D.3.2 pg 101
 * @see org.bouncycastle.math.ec.ECMultiplier#multiply(org.bouncycastle.math.ec.ECPoint, java.math.BigInteger)
 */
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:Appdome,项目名称:ipack,代码行数:30,代码来源:FpNafMultiplier.java

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

示例4: RSAKeyGenerationParameters

import java.math.BigInteger; //导入方法依赖的package包/类
public RSAKeyGenerationParameters(
    BigInteger      publicExponent,
    SecureRandom    random,
    int             strength,
    int             certainty)
{
    super(random, strength);

    if (strength < 12)
    {
        throw new IllegalArgumentException("key strength too small");
    }

    //
    // public exponent cannot be even
    //
    if (!publicExponent.testBit(0)) 
    {
            throw new IllegalArgumentException("public exponent cannot be even");
    }
    
    this.publicExponent = publicExponent;
    this.certainty = certainty;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:RSAKeyGenerationParameters.java

示例5: multiply

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Multiply a point with a big integer
 */
public static EcPoint multiply(EcPoint p, BigInteger k) {
   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:mithrilcoin-io,项目名称:EosCommander,代码行数:24,代码来源:EcTools.java

示例6: mul

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Based on Algorithm IV.1 on p. 63 of "Elliptic Curves in Cryptography"
 * by I. F. Blake, G. Seroussi, N. P. Smart.
 */
public ECPoint mul(BigInteger n, ECPoint P) {
	ECPoint Q;
	ECPoint S = new ECPointF2m();
	BigInteger k;

	if (n.compareTo(BigInteger.valueOf(0)) == 0)
		return new ECPointF2m();

	if (n.compareTo(BigInteger.valueOf(0)) < 0) {
		k = n.negate();
		Q = P.negate();
	} else {
		k = n;
		Q = P;
	}

	for (int j = k.bitLength() - 1; j >= 0; j--) {
		S = add(S, S);
		if (k.testBit(j)) {
			S = add(S, Q);
		}
	}

	return S;
}
 
开发者ID:sheraz-n,项目名称:Cryptguard,代码行数:30,代码来源:ECurveF2m.java

示例7: multiplyPointA

import java.math.BigInteger; //导入方法依赖的package包/类
public static BigInteger[] multiplyPointA(BigInteger[] P, BigInteger k,
    ECParameterSpec params) {
  BigInteger[] Q = new BigInteger[] {null, null};

  for (int i = k.bitLength() - 1; i >= 0; i--) {
    Q = doublePointA(Q, params);
    if (k.testBit(i)) Q = addPointsA(Q, P, params);
  }

  return Q;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:EcCore.java

示例8: implShamirsTrick

import java.math.BigInteger; //导入方法依赖的package包/类
private static ECPoint implShamirsTrick(ECPoint P, BigInteger k,
    ECPoint Q, BigInteger l)
{
    int m = Math.max(k.bitLength(), l.bitLength());
    ECPoint Z = P.add(Q);
    ECPoint R = P.getCurve().getInfinity();

    for (int i = m - 1; i >= 0; --i)
    {
        R = R.twice();

        if (k.testBit(i))
        {
            if (l.testBit(i))
            {
                R = R.add(Z);
            }
            else
            {
                R = R.add(P);
            }
        }
        else
        {
            if (l.testBit(i))
            {
                R = R.add(Q);
            }
        }
    }

    return R;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:34,代码来源:ECAlgorithms.java

示例9: multiply

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Simple shift-and-add multiplication. Serves as reference implementation
 * to verify (possibly faster) implementations in
 * {@link org.bouncycastle.math.ec.ECPoint ECPoint}.
 * 
 * @param p The point to multiply.
 * @param k The factor by which to multiply.
 * @return The result of the point multiplication <code>k * p</code>.
 */
public ECPoint multiply(ECPoint p, BigInteger k, PreCompInfo preCompInfo)
{
    ECPoint q = p.getCurve().getInfinity();
    int t = k.bitLength();
    for (int i = 0; i < t; i++)
    {
        if (k.testBit(i))
        {
            q = q.add(p);
        }
        p = p.twice();
    }
    return q;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:24,代码来源:ReferenceMultiplier.java

示例10: getFailureInfoText

import java.math.BigInteger; //导入方法依赖的package包/类
public static String getFailureInfoText(int failureInfo) {
    BigInteger bi = BigInteger.valueOf(failureInfo);
    final int n = Math.min(bi.bitLength(), FAILUREINFO_TEXTS.length);

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < n; i++) {
        if (bi.testBit(i)) {
            sb.append(", ").append(FAILUREINFO_TEXTS[i]);
        }
    }

    return (sb.length() < 3) ? "" : sb.substring(2);
}
 
开发者ID:xipki,项目名称:xitk,代码行数:14,代码来源:CmpFailureUtil.java

示例11: PointMul

import java.math.BigInteger; //导入方法依赖的package包/类
private static ECPoint PointMul(BigInteger k, ECPoint pt, EllipticCurve curve) {
	int len = k.bitLength();
	ECPoint Q = new ECPoint(pt.getAffineX(), pt.getAffineY());

	for (int i = len - 2; i >= 0; i--) {
		Q = PointAdd(Q, Q, curve);
		if (k.testBit(i)) {
			Q = PointAdd(Q, pt, curve);
		}
	}
	return Q;
}
 
开发者ID:bubicn,项目名称:bubichain-sdk-java,代码行数:13,代码来源:Sm2Key.java

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

示例13: isEven

import java.math.BigInteger; //导入方法依赖的package包/类
public static boolean isEven(BigInteger num) {
    int i = num.bitCount();
    return i == 0 || num.testBit(i);
}
 
开发者ID:Baizey,项目名称:Helpers,代码行数:5,代码来源:Numbers.java

示例14: windowNaf

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Computes the Window NAF (non-adjacent Form) of an integer.
 * @param width The width <code>w</code> of the Window NAF. The width is
 * defined as the minimal number <code>w</code>, such that for any
 * <code>w</code> consecutive digits in the resulting representation, at
 * most one is non-zero.
 * @param k The integer of which the Window NAF is computed.
 * @return The Window NAF of the given width, such that the following holds:
 * <code>k = &sum;<sub>i=0</sub><sup>l-1</sup> k<sub>i</sub>2<sup>i</sup>
 * </code>, where the <code>k<sub>i</sub></code> denote the elements of the
 * returned <code>byte[]</code>.
 */
public byte[] windowNaf(byte width, BigInteger k)
{
    // The window NAF is at most 1 element longer than the binary
    // representation of the integer k. byte can be used instead of short or
    // int unless the window width is larger than 8. For larger width use
    // short or int. However, a width of more than 8 is not efficient for
    // m = log2(q) smaller than 2305 Bits. Note: Values for m larger than
    // 1000 Bits are currently not used in practice.
    byte[] wnaf = new byte[k.bitLength() + 1];

    // 2^width as short and BigInteger
    short pow2wB = (short)(1 << width);
    BigInteger pow2wBI = BigInteger.valueOf(pow2wB);

    int i = 0;

    // The actual length of the WNAF
    int length = 0;

    // while k >= 1
    while (k.signum() > 0)
    {
        // if k is odd
        if (k.testBit(0))
        {
            // k mod 2^width
            BigInteger remainder = k.mod(pow2wBI);

            // if remainder > 2^(width - 1) - 1
            if (remainder.testBit(width - 1))
            {
                wnaf[i] = (byte)(remainder.intValue() - pow2wB);
            }
            else
            {
                wnaf[i] = (byte)remainder.intValue();
            }
            // wnaf[i] is now in [-2^(width-1), 2^(width-1)-1]

            k = k.subtract(BigInteger.valueOf(wnaf[i]));
            length = i;
        }
        else
        {
            wnaf[i] = 0;
        }

        // k = k/2
        k = k.shiftRight(1);
        i++;
    }

    length++;

    // Reduce the WNAF array to its actual length
    byte[] wnafShort = new byte[length];
    System.arraycopy(wnaf, 0, wnafShort, 0, length);
    return wnafShort;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:72,代码来源:WNafMultiplier.java

示例15: lucasSequence

import java.math.BigInteger; //导入方法依赖的package包/类
private static BigInteger[] lucasSequence(
    BigInteger  p,
    BigInteger  P,
    BigInteger  Q,
    BigInteger  k)
{
    int n = k.bitLength();
    int s = k.getLowestSetBit();

    BigInteger Uh = ECConstants.ONE;
    BigInteger Vl = ECConstants.TWO;
    BigInteger Vh = P;
    BigInteger Ql = ECConstants.ONE;
    BigInteger Qh = ECConstants.ONE;

    for (int j = n - 1; j >= s + 1; --j)
    {
        Ql = Ql.multiply(Qh).mod(p);

        if (k.testBit(j))
        {
            Qh = Ql.multiply(Q).mod(p);
            Uh = Uh.multiply(Vh).mod(p);
            Vl = Vh.multiply(Vl).subtract(P.multiply(Ql)).mod(p);
            Vh = Vh.multiply(Vh).subtract(Qh.shiftLeft(1)).mod(p);
        }
        else
        {
            Qh = Ql;
            Uh = Uh.multiply(Vl).subtract(Ql).mod(p);
            Vh = Vh.multiply(Vl).subtract(P.multiply(Ql)).mod(p);
            Vl = Vl.multiply(Vl).subtract(Ql.shiftLeft(1)).mod(p);
        }
    }

    Ql = Ql.multiply(Qh).mod(p);
    Qh = Ql.multiply(Q).mod(p);
    Uh = Uh.multiply(Vl).subtract(Ql).mod(p);
    Vl = Vh.multiply(Vl).subtract(P.multiply(Ql)).mod(p);
    Ql = Ql.multiply(Qh).mod(p);

    for (int j = 1; j <= s; ++j)
    {
        Uh = Uh.multiply(Vl).mod(p);
        Vl = Vl.multiply(Vl).subtract(Ql.shiftLeft(1)).mod(p);
        Ql = Ql.multiply(Ql).mod(p);
    }

    return new BigInteger[]{ Uh, Vl };
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:51,代码来源:ECFieldElement.java


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