-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomBigInt.cs
More file actions
31 lines (27 loc) · 938 Bytes
/
RandomBigInt.cs
File metadata and controls
31 lines (27 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System.Linq;
using ECClasses;
using System.Security.Cryptography;
using System.Numerics;
namespace ECCryptoSystem
{
public class RandomBigInt
{
// возращает большое рандомное целое
public static BigInteger randomBigInteger(ECurve curve)
{
byte[] unsignedBytes = new byte[] { 0x00 };
byte[] randomBytes = new byte[curve.Length / 8];
RandomNumberGenerator randomNumberGenerator = RandomNumberGenerator.Create();
randomNumberGenerator.GetBytes(randomBytes);
byte[] positiveRandomBytes = randomBytes.Concat(unsignedBytes).ToArray();
BigInteger randomValue = new BigInteger(positiveRandomBytes);
BigInteger result;
do
{
result = randomValue % curve.N;
}
while (result == 0);
return result;
}
}
}