本文整理汇总了C#中System.Numerics.BigInteger.Convert方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.Convert方法的具体用法?C# BigInteger.Convert怎么用?C# BigInteger.Convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Numerics.BigInteger
的用法示例。
在下文中一共展示了BigInteger.Convert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRandomLargePrime
/// <summary>
/// Generates a random large prime near the given bit size.
/// </summary>
/// <param name="generator"></param>
/// <param name="size"></param>
/// <returns></returns>
private static BigInteger GetRandomLargePrime(IBasylKeyGenerator generator, int size)
{
//fills an array with random bytes. This is used for the prime search.
byte[] vals = new byte[(int)Math.Ceiling(size / 8.0f)];
lock (generator)
{
for (int i = 0; i < 20; i++)
{
generator.FillBytes(vals);
}
for (int k = 0; k < 2; k++)
for (int i = 0; i < vals.Length; i++)
{
for (int n = 0; n < 3; n++)
generator.GetRandomByte();
generator.EncryptByte(ref vals[i]);
}
}
//searches for the prime number, decreases until it finds one that tests to be prime.
BigInteger gco = new BigInteger(vals);
if(gco < 0)
{
gco *= -1;
}
if (gco.IsEven)
{
gco -= 1;
}
var bouncyCastleBig = gco.Convert();
var amt = new BigInteger(2).Convert();
while (!bouncyCastleBig.IsProbablePrime(1))
{
bouncyCastleBig = bouncyCastleBig.Subtract(amt);
gco -= 2;
}
//Bouncy castles isProbablePrime method is severely optimized compared to a naive approach.
return gco;
}