本文整理汇总了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} > {@code k} >= 1) or a
* pentanomial (X^{@code m} + X^{@code k3}
* + X^{@code k2} + X^{@code k1} + 1 with
* {@code m} > {@code k3} > {@code k2}
* > {@code k1} >= 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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例6: tauAdicNaf
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Computes the <code>τ</code>-adic NAF (non-adjacent form) of an
* element <code>λ</code> of <code><b>Z</b>[τ]</code>.
* @param mu The parameter <code>μ</code> of the elliptic curve.
* @param lambda The element <code>λ</code> of
* <code><b>Z</b>[τ]</code>.
* @return The <code>τ</code>-adic NAF of <code>λ</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;
}
示例7: tauAdicNaf
import java.math.BigInteger; //导入方法依赖的package包/类
/**
* Computes the <code>τ</code>-adic NAF (non-adjacent form) of an
* element <code>λ</code> of <code><b>Z</b>[τ]</code>.
* @param mu The parameter <code>μ</code> of the elliptic curve.
* @param lambda The element <code>λ</code> of
* <code><b>Z</b>[τ]</code>.
* @return The <code>τ</code>-adic NAF of <code>λ</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;
}