本文整理汇总了C#中Mono.Math.BigInteger.testBit方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.testBit方法的具体用法?C# BigInteger.testBit怎么用?C# BigInteger.testBit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.testBit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EvenPow
public BigInteger EvenPow(BigInteger b, BigInteger exp)
{
BigInteger resultNum = new BigInteger((BigInteger)1, mod.length << 1);
BigInteger tempNum = new BigInteger(b % mod, mod.length << 1); // ensures (tempNum * tempNum) < b^ (2k)
uint totalBits = (uint)exp.bitCount();
uint[] wkspace = new uint[mod.length << 1];
// perform squaring and multiply exponentiation
for (uint pos = 0; pos < totalBits; pos++)
{
if (exp.testBit(pos))
{
Array.Clear(wkspace, 0, wkspace.Length);
Kernel.Multiply(resultNum.data, 0, resultNum.length, tempNum.data, 0, tempNum.length, wkspace, 0);
resultNum.length += tempNum.length;
uint[] t = wkspace;
wkspace = resultNum.data;
resultNum.data = t;
BarrettReduction(resultNum);
}
Kernel.SquarePositive(tempNum, ref wkspace);
BarrettReduction(tempNum);
if (tempNum == 1)
{
return resultNum;
}
}
return resultNum;
}
示例2: OddModTwoPow
private unsafe BigInteger OddModTwoPow(BigInteger exp)
{
uint[] wkspace = new uint[mod.length << 1 + 1];
BigInteger resultNum = Montgomery.ToMont((BigInteger)2, this.mod);
resultNum = new BigInteger(resultNum, mod.length << 1 + 1);
uint mPrime = Montgomery.Inverse(mod.data[0]);
//
// TODO: eat small bits, the ones we can do with no modular reduction
//
uint pos = (uint)exp.bitCount() - 2;
do
{
Kernel.SquarePositive(resultNum, ref wkspace);
resultNum = Montgomery.Reduce(resultNum, mod, mPrime);
if (exp.testBit(pos))
{
//
// resultNum = (resultNum * 2) % mod
//
fixed (uint* u = resultNum.data)
{
//
// Double
//
uint* uu = u;
uint* uuE = u + resultNum.length;
uint x, carry = 0;
while (uu < uuE)
{
x = *uu;
*uu = (x << 1) | carry;
carry = x >> (32 - 1);
uu++;
}
// subtraction inlined because we know it is square
if (carry != 0 || resultNum >= mod)
{
fixed (uint* s = mod.data)
{
uu = u;
uint c = 0;
uint* ss = s;
do
{
uint a = *ss++;
if (((a += c) < c) | ((*(uu++) -= a) > ~a))
c = 1;
else
c = 0;
} while (uu < uuE);
}
}
}
}
} while (pos-- > 0);
resultNum = Montgomery.Reduce(resultNum, mod, mPrime);
return resultNum;
}
示例3: OddPow
private BigInteger OddPow(BigInteger b, BigInteger exp)
{
BigInteger resultNum = new BigInteger(Montgomery.ToMont(1, mod), mod.length << 1);
BigInteger tempNum = new BigInteger(Montgomery.ToMont(b, mod), mod.length << 1); // ensures (tempNum * tempNum) < b^ (2k)
uint mPrime = Montgomery.Inverse(mod.data[0]);
uint totalBits = (uint)exp.bitCount();
uint[] wkspace = new uint[mod.length << 1];
// perform squaring and multiply exponentiation
for (uint pos = 0; pos < totalBits; pos++)
{
if (exp.testBit(pos))
{
Array.Clear(wkspace, 0, wkspace.Length);
Kernel.Multiply(resultNum.data, 0, resultNum.length, tempNum.data, 0, tempNum.length, wkspace, 0);
resultNum.length += tempNum.length;
uint[] t = wkspace;
wkspace = resultNum.data;
resultNum.data = t;
Montgomery.Reduce(resultNum, mod, mPrime);
}
Kernel.SquarePositive(tempNum, ref wkspace);
Montgomery.Reduce(tempNum, mod, mPrime);
}
Montgomery.Reduce(resultNum, mod, mPrime);
return resultNum;
}
示例4: IsPrimeAcceptable
protected override bool IsPrimeAcceptable (BigInteger bi, object Context)
{
return bi.testBit (1);
}