本文整理汇总了C#中Org.BouncyCastle.Math.BigInteger.IsEqualMagnitude方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.IsEqualMagnitude方法的具体用法?C# BigInteger.IsEqualMagnitude怎么用?C# BigInteger.IsEqualMagnitude使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Org.BouncyCastle.Math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.IsEqualMagnitude方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RabinMillerTest
public bool RabinMillerTest(int certainty, Random random)
{
Debug.Assert(certainty > 0);
Debug.Assert(BitLength > 2);
Debug.Assert(TestBit(0));
// let n = 1 + d . 2^s
BigInteger n = this;
int s = n.GetLowestSetBitMaskFirst(-1 << 1);
Debug.Assert(s >= 1);
BigInteger r = n.ShiftRight(s);
// NOTE: Avoid conversion to/from Montgomery form and check for R/-R as result instead
BigInteger montRadix = One.ShiftLeft(32 * n.magnitude.Length).Remainder(n);
BigInteger minusMontRadix = n.Subtract(montRadix);
do
{
BigInteger a;
do
{
a = new BigInteger(n.BitLength, random);
}
while (a.sign == 0 || a.CompareTo(n) >= 0
|| a.IsEqualMagnitude(montRadix) || a.IsEqualMagnitude(minusMontRadix));
BigInteger y = ModPowMonty(a, r, n, false);
if (!y.Equals(montRadix))
{
int j = 0;
while (!y.Equals(minusMontRadix))
{
if (++j == s)
return false;
y = ModPowMonty(y, Two, n, false);
if (y.Equals(montRadix))
return false;
}
}
certainty -= 2; // composites pass for only 1/4 possible 'a'
}
while (certainty > 0);
return true;
}
示例2: RabinMillerTest
internal bool RabinMillerTest(int certainty, Random random, bool randomlySelected)
{
int bits = BitLength;
Debug.Assert(certainty > 0);
Debug.Assert(bits > 2);
Debug.Assert(TestBit(0));
int iterations = ((certainty - 1) / 2) + 1;
if (randomlySelected)
{
int itersFor100Cert = bits >= 1024 ? 4
: bits >= 512 ? 8
: bits >= 256 ? 16
: 50;
if (certainty < 100)
{
iterations = System.Math.Min(itersFor100Cert, iterations);
}
else
{
iterations -= 50;
iterations += itersFor100Cert;
}
}
// let n = 1 + d . 2^s
BigInteger n = this;
int s = n.GetLowestSetBitMaskFirst(-1 << 1);
Debug.Assert(s >= 1);
BigInteger r = n.ShiftRight(s);
// NOTE: Avoid conversion to/from Montgomery form and check for R/-R as result instead
BigInteger montRadix = One.ShiftLeft(32 * n.magnitude.Length).Remainder(n);
BigInteger minusMontRadix = n.Subtract(montRadix);
do
{
BigInteger a;
do
{
a = new BigInteger(n.BitLength, random);
}
while (a.sign == 0 || a.CompareTo(n) >= 0
|| a.IsEqualMagnitude(montRadix) || a.IsEqualMagnitude(minusMontRadix));
BigInteger y = ModPowMonty(a, r, n, false);
if (!y.Equals(montRadix))
{
int j = 0;
while (!y.Equals(minusMontRadix))
{
if (++j == s)
return false;
y = ModPowMonty(y, Two, n, false);
if (y.Equals(montRadix))
return false;
}
}
}
while (--iterations > 0);
return true;
}