Shamir Secret Sharing (Rebuild)Shamir's secret sharing method generates a number of shares, of which a threshold defines the number of shares which can be used to re-build the message. [Encoder][Theory] |
Presentation
Code Used
[HttpPost] public ActionResult shamir(FormCollection form) { string shares = ""; int nshares = 2; int nthreshold = 2; List<String> results = new List<String>(); string secret = (string)form["message"]; string sh = (string)form["nshares"]; string th = (string)form["nthreshold"]; SSharp shamir = new SSharp(); try { nshares = Convert.ToInt32(sh); nthreshold = Convert.ToInt32(th); results = shamir.CreateShares((int)nthreshold, (int)nshares, secret); foreach (String s in results) { shares += s + Environment.NewLine; } } catch { } ViewData["shares"] = shares; // Reconstruct shamir = new SSharp(); String result = shamir.RebuildSecret((int)nthreshold, results); string reconstructed = result; ViewData["recon"] = reconstructed; return PartialView("shamir_partial"); }
Blog
A related blog is here