本文整理汇总了C#中System.Numerics.BigInteger.First方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.First方法的具体用法?C# BigInteger.First怎么用?C# BigInteger.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Numerics.BigInteger
的用法示例。
在下文中一共展示了BigInteger.First方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decrypt
public byte[] Decrypt(byte[] message, PrivateKey privateKey, PublicKey publicKey)
{
var keySize = publicKey.n.ToByteArray().Length;
var encryptedBlockSize = keySize;
var sourceBlockSize = keySize - preffix.Length - 2;
var numberBlocks = message.Length / encryptedBlockSize;
if (message.Length % encryptedBlockSize != 0)
throw new ArgumentException("Wrong size of encrypted message");
var decryptedMessage = new byte[numberBlocks * sourceBlockSize];
Parallel.For(0, numberBlocks, (i) =>
//for (var i = 0; i < numberBlocks; i++)
{
var part = new byte[encryptedBlockSize];
Array.Copy(message, i * encryptedBlockSize, part, 0, encryptedBlockSize);
var Mi = new BigInteger(part);
var D = (publicKey.b * publicKey.b + 4 * Mi) % publicKey.n;
//var s = BigInteger.ModPow(D, (privateKey.p + 1) / 4, privateKey.p);
//var r = BigInteger.ModPow(D, (privateKey.q + 1) / 4, privateKey.q);
var s = BigIntegerHelper.fast_exp(D, (privateKey.p + 1) / 4, privateKey.p);
var r = BigIntegerHelper.fast_exp(D, (privateKey.q + 1) / 4, privateKey.q);
BigInteger yp, yq;
BigInteger d = 1;
ExtendedEuclid(privateKey.p, privateKey.q, out yp, out yq, out d);
var roots = new BigInteger[4];
roots[0] = BigInteger.Abs(yp * privateKey.p * r + yq * privateKey.q * s);
roots[1] = (-roots[0]) % publicKey.n + publicKey.n;
roots[0] = roots[0] % publicKey.n;
roots[2] = BigInteger.Abs(yp * privateKey.p * r - yq * privateKey.q * s);
roots[3] = (-roots[2]) % publicKey.n + publicKey.n;
roots[2] = roots[2] % publicKey.n;
for (var j = 0; j < 4; j++)
{
roots[j] = ((-publicKey.b + roots[j]) / 2) % publicKey.n;
roots[j] = roots[j] < 0 ? roots[j] + publicKey.n : roots[j];
}
var rightRoot = roots.First(num => num.ToByteArray().Skip(sourceBlockSize).Take(preffix.Length).SequenceEqual(preffix));
Array.Copy(rightRoot.ToByteArray(), 0, decryptedMessage, i * sourceBlockSize, sourceBlockSize);
});
return decryptedMessage;
}