本文整理汇总了C#中Lidgren.Network.NetBigInteger.ModInverse方法的典型用法代码示例。如果您正苦于以下问题:C# NetBigInteger.ModInverse方法的具体用法?C# NetBigInteger.ModInverse怎么用?C# NetBigInteger.ModInverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetBigInteger
的用法示例。
在下文中一共展示了NetBigInteger.ModInverse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModPow
//.........这里部分代码省略.........
}
yAccum = new int[m.m_magnitude.Length * 2];
}
yVal = new int[m.m_magnitude.Length];
//
// from LSW to MSW
//
for (int i = 0; i < exponent.m_magnitude.Length; i++)
{
int v = exponent.m_magnitude[i];
int bits = 0;
if (i == 0)
{
while (v > 0)
{
v <<= 1;
bits++;
}
//
// first time in initialise y
//
zVal.CopyTo(yVal, 0);
v <<= 1;
bits++;
}
while (v != 0)
{
if (useMonty)
{
// Montgomery square algo doesn't exist, and a normal
// square followed by a Montgomery reduction proved to
// be almost as heavy as a Montgomery mulitply.
MultiplyMonty(yAccum, yVal, yVal, m.m_magnitude, mQ);
}
else
{
Square(yAccum, yVal);
Remainder(yAccum, m.m_magnitude);
Array.Copy(yAccum, yAccum.Length - yVal.Length, yVal, 0, yVal.Length);
ZeroOut(yAccum);
}
bits++;
if (v < 0)
{
if (useMonty)
{
MultiplyMonty(yAccum, yVal, zVal, m.m_magnitude, mQ);
}
else
{
Multiply(yAccum, yVal, zVal);
Remainder(yAccum, m.m_magnitude);
Array.Copy(yAccum, yAccum.Length - yVal.Length, yVal, 0,
yVal.Length);
ZeroOut(yAccum);
}
}
v <<= 1;
}
while (bits < 32)
{
if (useMonty)
{
MultiplyMonty(yAccum, yVal, yVal, m.m_magnitude, mQ);
}
else
{
Square(yAccum, yVal);
Remainder(yAccum, m.m_magnitude);
Array.Copy(yAccum, yAccum.Length - yVal.Length, yVal, 0, yVal.Length);
ZeroOut(yAccum);
}
bits++;
}
}
if (useMonty)
{
// Return y * R^(-1) mod m by doing y * 1 * R^(-1) mod m
ZeroOut(zVal);
zVal[zVal.Length - 1] = 1;
MultiplyMonty(yAccum, yVal, zVal, m.m_magnitude, mQ);
}
NetBigInteger result = new NetBigInteger(1, yVal, true);
return exponent.m_sign > 0
? result
: result.ModInverse(m);
}