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


Java BigInteger.clearBit方法代码示例

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


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

示例1: ECFieldF2m

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Creates an elliptic curve characteristic 2 finite
 * field which has 2^{@code m} elements with
 * polynomial basis.
 * The reduction polynomial for this field is based
 * on {@code rp} whose i-th bit corresponds to
 * the i-th coefficient of the reduction polynomial.<p>
 * Note: A valid reduction polynomial is either a
 * trinomial (X^{@code m} + X^{@code k} + 1
 * with {@code m} &gt; {@code k} &gt;= 1) or a
 * pentanomial (X^{@code m} + X^{@code k3}
 * + X^{@code k2} + X^{@code k1} + 1 with
 * {@code m} &gt; {@code k3} &gt; {@code k2}
 * &gt; {@code k1} &gt;= 1).
 * @param m with 2^{@code m} being the number of elements.
 * @param rp the BigInteger whose i-th bit corresponds to
 * the i-th coefficient of the reduction polynomial.
 * @exception NullPointerException if {@code rp} is null.
 * @exception IllegalArgumentException if {@code m}
 * is not positive, or {@code rp} does not represent
 * a valid reduction polynomial.
 */
public ECFieldF2m(int m, BigInteger rp) {
    // check m and rp
    this.m = m;
    this.rp = rp;
    if (m <= 0) {
        throw new IllegalArgumentException("m is not positive");
    }
    int bitCount = this.rp.bitCount();
    if (!this.rp.testBit(0) || !this.rp.testBit(m) ||
        ((bitCount != 3) && (bitCount != 5))) {
        throw new IllegalArgumentException
            ("rp does not represent a valid reduction polynomial");
    }
    // convert rp into ks
    BigInteger temp = this.rp.clearBit(0).clearBit(m);
    this.ks = new int[bitCount-2];
    for (int i = this.ks.length-1; i >= 0; i--) {
        int index = temp.getLowestSetBit();
        this.ks[i] = index;
        temp = temp.clearBit(index);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:45,代码来源:ECFieldF2m.java

示例2: hash2FieldElement

import java.math.BigInteger; //导入方法依赖的package包/类
private static ECFieldElement hash2FieldElement(ECCurve curve, byte[] hash)
{
    byte[] data = Arrays.clone(hash);
    reverseBytes(data);
    BigInteger num = new BigInteger(1, data);
    while (num.bitLength() >= curve.getFieldSize())
    {
        num = num.clearBit(num.bitLength() - 1);
    }

    return curve.fromBigInteger(num);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:DSTU4145Signer.java

示例3: fieldElement2Integer

import java.math.BigInteger; //导入方法依赖的package包/类
private static BigInteger fieldElement2Integer(BigInteger n, ECFieldElement fieldElement)
{
    BigInteger num = fieldElement.toBigInteger();
    while (num.bitLength() >= n.bitLength())
    {
        num = num.clearBit(num.bitLength() - 1);
    }

    return num;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:11,代码来源:DSTU4145Signer.java

示例4: getMaskedAddress

import java.math.BigInteger; //导入方法依赖的package包/类
private BigInteger getMaskedAddress(boolean one) {
    BigInteger numAddress = netAddress;
    int numBits;
    if (isV4) {
        numBits = 32 - networkMask;
    } else {
        numBits = 128 - networkMask;
    }
    for (int i = 0; i < numBits; i++) {
        if (one) numAddress = numAddress.setBit(i);
        else numAddress = numAddress.clearBit(i);
    }
    return numAddress;
}
 
开发者ID:akashdeepsingh9988,项目名称:Cybernet-VPN,代码行数:15,代码来源:NetworkSpace.java

示例5: Decode

import java.math.BigInteger; //导入方法依赖的package包/类
static long Decode(String idString, final String prefix) throws IllegalArgumentException {

			idString = idString.trim().toUpperCase();

			if (idString.length() != ID_LEN + prefix.length()) {
				throw new IllegalArgumentException(idString);
			}

			BigInteger idB = BigInteger.ZERO;
			for (int i = ID_LEN + prefix.length() - 1; i > prefix.length(); i--) {
				int p = alphabet.indexOf(idString.charAt(i));
				if (p >= 0) {

					idB = idB.shiftLeft(5);
					idB = idB.add(BigInteger.valueOf(p));
				}
			}
			for (int i = 64; i < 75; i++) {
				idB = idB.clearBit(i);
			}

			long id = idB.longValue();

			if (!idString.equals(Encode(id, prefix))) {
				throw new IllegalArgumentException(idString);
			}

			return id;
		}
 
开发者ID:EonTechnology,项目名称:server,代码行数:30,代码来源:Format.java

示例6: tauAdicNaf

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Computes the <code>&tau;</code>-adic NAF (non-adjacent form) of an
 * element <code>&lambda;</code> of <code><b>Z</b>[&tau;]</code>.
 * @param mu The parameter <code>&mu;</code> of the elliptic curve.
 * @param lambda The element <code>&lambda;</code> of
 * <code><b>Z</b>[&tau;]</code>.
 * @return The <code>&tau;</code>-adic NAF of <code>&lambda;</code>.
 */
public static byte[] tauAdicNaf(byte mu, ZTauElement lambda)
{
    if (!((mu == 1) || (mu == -1)))
    {
        throw new IllegalArgumentException("mu must be 1 or -1");
    }
    
    BigInteger norm = norm(mu, lambda);

    // Ceiling of log2 of the norm 
    int log2Norm = norm.bitLength();

    // If length(TNAF) > 30, then length(TNAF) < log2Norm + 3.52
    int maxLength = log2Norm > 30 ? log2Norm + 4 : 34;

    // The array holding the TNAF
    byte[] u = new byte[maxLength];
    int i = 0;

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

    BigInteger r0 = lambda.u;
    BigInteger r1 = lambda.v;

    while(!((r0.equals(ECConstants.ZERO)) && (r1.equals(ECConstants.ZERO))))
    {
        // If r0 is odd
        if (r0.testBit(0))
        {
            u[i] = (byte) ECConstants.TWO.subtract((r0.subtract(r1.shiftLeft(1))).mod(ECConstants.FOUR)).intValue();

            // r0 = r0 - u[i]
            if (u[i] == 1)
            {
                r0 = r0.clearBit(0);
            }
            else
            {
                // u[i] == -1
                r0 = r0.add(ECConstants.ONE);
            }
            length = i;
        }
        else
        {
            u[i] = 0;
        }

        BigInteger t = r0;
        BigInteger s = r0.shiftRight(1);
        if (mu == 1)
        {
            r0 = r1.add(s);
        }
        else
        {
            // mu == -1
            r0 = r1.subtract(s);
        }

        r1 = t.shiftRight(1).negate();
        i++;
    }

    length++;

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

示例7: tauAdicNaf

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Computes the <code>&tau;</code>-adic NAF (non-adjacent form) of an
 * element <code>&lambda;</code> of <code><b>Z</b>[&tau;]</code>.
 * @param mu The parameter <code>&mu;</code> of the elliptic curve.
 * @param lambda The element <code>&lambda;</code> of
 * <code><b>Z</b>[&tau;]</code>.
 * @return The <code>&tau;</code>-adic NAF of <code>&lambda;</code>.
 */
public static byte[] tauAdicNaf(byte mu, ZTauElement lambda)
{
    if (!((mu == 1) || (mu == -1)))
    {
        throw new IllegalArgumentException("mu must be 1 or -1");
    }

    BigInteger norm = norm(mu, lambda);

    // Ceiling of log2 of the norm
    int log2Norm = norm.bitLength();

    // If length(TNAF) > 30, then length(TNAF) < log2Norm + 3.52
    int maxLength = log2Norm > 30 ? log2Norm + 4 : 34;

    // The array holding the TNAF
    byte[] u = new byte[maxLength];
    int i = 0;

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

    BigInteger r0 = lambda.u;
    BigInteger r1 = lambda.v;

    while(!((r0.equals(ECConstants.ZERO)) && (r1.equals(ECConstants.ZERO))))
    {
        // If r0 is odd
        if (r0.testBit(0))
        {
            u[i] = (byte) ECConstants.TWO.subtract((r0.subtract(r1.shiftLeft(1))).mod(ECConstants.FOUR)).intValue();

            // r0 = r0 - u[i]
            if (u[i] == 1)
            {
                r0 = r0.clearBit(0);
            }
            else
            {
                // u[i] == -1
                r0 = r0.add(ECConstants.ONE);
            }
            length = i;
        }
        else
        {
            u[i] = 0;
        }

        BigInteger t = r0;
        BigInteger s = r0.shiftRight(1);
        if (mu == 1)
        {
            r0 = r1.add(s);
        }
        else
        {
            // mu == -1
            r0 = r1.subtract(s);
        }

        r1 = t.shiftRight(1).negate();
        i++;
    }

    length++;

    // Reduce the TNAF array to its actual length
    byte[] tnaf = new byte[length];
    System.arraycopy(u, 0, tnaf, 0, length);
    return tnaf;
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:81,代码来源:Tnaf.java


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