本文整理汇总了C#中Org.BouncyCastle.Math.BigInteger.Square方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.Square方法的具体用法?C# BigInteger.Square怎么用?C# BigInteger.Square使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Org.BouncyCastle.Math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.Square方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModPowBarrett
private static BigInteger ModPowBarrett(BigInteger b, BigInteger e, BigInteger m)
{
int k = m.magnitude.Length;
BigInteger mr = One.ShiftLeft((k + 1) << 5);
BigInteger yu = One.ShiftLeft(k << 6).Divide(m);
// Sliding window from MSW to LSW
int extraBits = 0, expLength = e.BitLength;
while (expLength > ExpWindowThresholds[extraBits])
{
++extraBits;
}
int numPowers = 1 << extraBits;
BigInteger[] oddPowers = new BigInteger[numPowers];
oddPowers[0] = b;
BigInteger b2 = ReduceBarrett(b.Square(), m, mr, yu);
for (int i = 1; i < numPowers; ++i)
{
oddPowers[i] = ReduceBarrett(oddPowers[i - 1].Multiply(b2), m, mr, yu);
}
int[] windowList = GetWindowList(e.magnitude, extraBits);
Debug.Assert(windowList.Length > 0);
int window = windowList[0];
int mult = window & 0xFF, lastZeroes = window >> 8;
BigInteger y;
if (mult == 1)
{
y = b2;
--lastZeroes;
}
else
{
y = oddPowers[mult >> 1];
}
int windowPos = 1;
while ((window = windowList[windowPos++]) != -1)
{
mult = window & 0xFF;
int bits = lastZeroes + BitLengthTable[mult];
for (int j = 0; j < bits; ++j)
{
y = ReduceBarrett(y.Square(), m, mr, yu);
}
y = ReduceBarrett(y.Multiply(oddPowers[mult >> 1]), m, mr, yu);
lastZeroes = window >> 8;
}
for (int i = 0; i < lastZeroes; ++i)
{
y = ReduceBarrett(y.Square(), m, mr, yu);
}
return y;
}