public static List <int> nthNumberGenerator(int t, int k) { var list = new List <int>(); for (int i = 0; i < t - 1; i++) { Thread.Sleep(100); list.Add(SMCalculations.randomNumber(0, k)); } return(list); }
public static void ShamirMeth() { Console.WriteLine("=== Shamir Scheme ==="); Console.Write("Enter k value: "); int _k = int.Parse(Console.ReadLine()); Console.Write("Enter n value: "); int _n = int.Parse(Console.ReadLine()); Console.Write("Enter t value: "); int _t = int.Parse(Console.ReadLine()); Console.WriteLine($"Value of k: {_k}, n: {_n}, t: {_t}"); Stopwatch sw = Stopwatch.StartNew(); sw.Start(); //int _s = 954; var _s = SMCalculations.randomNumber(0, (int)_k); sw.Stop(); Console.WriteLine($"Value of secret: {_s}| Generation time [ms]: {sw.Elapsed}"); sw.Start(); int _p = _s - 1; do { _p = SMCalculations.randomIntegerPrime(0, (int)_k); } while (_p <= _s || _p <= _n); sw.Stop(); Console.WriteLine($"Value of p: {_p}| Generation time [ms]: {sw.Elapsed}"); var shList = nthNumberGenerator(_t, _k); var shareholderDict = DivisonSecret(shList, _n, _t, _s, _p); foreach (var element in shareholderDict) { Console.Write($" {element.Value}"); } Console.WriteLine(); var recreateSecret = RecreateSecret(shareholderDict, _t, _p); Console.WriteLine($"Recreate Secret: {recreateSecret}"); }