public byte[] Generate(int degree, byte input) { var polynomial = new byte[degree + 1]; do { _rng.GetBytes(polynomial); } while (Degree(polynomial) != degree); polynomial[0] = input; return(polynomial); }
public IEnumerable <byte[]> Split(byte[] secret, int parts, int minimum) { var values = new byte[parts][]; var length = secret.Length; for (var i = 0; i < parts; i++) { values[i] = new byte[length]; } for (var i = 0; i < length; i++) { var polynomial = _gf256.Generate(minimum - 1, secret[i]); for (var j = 0; j < parts; j++) { values[j][i] = _gf256.Evaluate(polynomial, (byte)(j + 1)); } } var result = new List <byte[]>(); for (var i = 0; i < parts; i++) { var value = new byte[length + 1]; _rng.GetBytes(value); // Note, this is to make the output look more random, but limits parts to 16 value[0] = (byte)((value[0] & 0xF0) + i + 1); Array.Copy(values[i], 0, value, 1, length); result.Add(value); } return(result); }
public static double GetDouble(this IRng rng) => BitConverter.ToDouble(rng.GetBytes(8), 0);
public static long GetInt64(this IRng rng) { var bytes = rng.GetBytes(8); return(BitConverter.ToInt64(bytes, 0)); }
public static int GetInt32(this IRng rng) { var bytes = rng.GetBytes(4); return(BitConverter.ToInt32(bytes, 0)); }