本文整理汇总了C#中System.Numerics.BigInteger.IsProbablePrime方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.IsProbablePrime方法的具体用法?C# BigInteger.IsProbablePrime怎么用?C# BigInteger.IsProbablePrime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Numerics.BigInteger
的用法示例。
在下文中一共展示了BigInteger.IsProbablePrime方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate_ab
public void Generate_ab()
{
byte[] bytes = new byte[KeySize / 8];
BigInteger _a = new BigInteger(bytes);
RandomNumberGenerator rng = RandomNumberGenerator.Create();
while (!_a.IsProbablePrime(KeySize) || _a >= P)
{
rng.GetBytes(bytes);
byte[] temp = new byte[bytes.Length + 1];
Array.Copy(bytes, temp, bytes.Length);
_a = new BigInteger(temp);
}
bytes = new byte[KeySize / 8];
BigInteger _b = new BigInteger(bytes);
while (!_b.IsProbablePrime(KeySize) || _b >= P)
{
rng.GetBytes(bytes);
byte[] temp = new byte[bytes.Length + 1];
Array.Copy(bytes, temp, bytes.Length);
_b = new BigInteger(temp);
}
a = _a;
b = _b;
}
示例2: GeneratePG
public void GeneratePG()
{
byte[] bytes = new byte[KeySize / 8];
BigInteger p = new BigInteger(bytes);
RandomNumberGenerator rng = RandomNumberGenerator.Create();
while (!p.IsProbablePrime(KeySize))
{
rng.GetBytes(bytes);
byte[] temp = new byte[bytes.Length + 1];
Array.Copy(bytes, temp, bytes.Length);
p = new BigInteger(temp);
}
bytes = new byte[KeySize / 8];
BigInteger g = new BigInteger(bytes);
while (!g.IsProbablePrime(KeySize) || g >= p)
{
rng.GetBytes(bytes);
byte[] temp = new byte[bytes.Length + 1];
Array.Copy(bytes, temp, bytes.Length);
g = new BigInteger(temp);
}
P = p;
G = g;
}
示例3: GenPrimeBigInteger
public static BigInteger GenPrimeBigInteger(byte length)
{
RandomNumberGenerator rng = RandomNumberGenerator.Create();
byte[] bytes = new byte[length];
BigInteger a;
int i = 0;
do
{
i++;
rng.GetBytes(bytes);
a = new BigInteger(bytes);
} while (!a.IsProbablePrime(1));
return a;
}
示例4: GetRandomPrime
public async Task<IHttpActionResult> GetRandomPrime()
{
var rnd = new System.Security.Cryptography.RNGCryptoServiceProvider();
var bytes = new byte[16];
var result = await Task.Run(() =>
{
rnd.GetNonZeroBytes(bytes);
var res = new BigInteger(bytes);
while (!res.IsProbablePrime(10))
{
rnd.GetNonZeroBytes(bytes);
res = new BigInteger(bytes);
}
return res;
});
Debug.WriteLine(result);
return Json(result.ToString());
}