// // GET: /Home/Details/5 public ActionResult DetectThreshold(string access) { var start = DateTime.Now; if (!string.IsNullOrEmpty(access)) { try { AccessStructure acc = new AccessStructure(access); var expanded = new List <QualifiedSubset>(); var qualified = new List <QualifiedSubset>(); var thresholds = new List <ThresholdSubset>(); var remaining = new List <QualifiedSubset>(); var attempts = new List <String>(); var tryIntersect = true; ThresholdHelper.ServeThresholdDetection(acc, tryIntersect, out expanded, out qualified, out thresholds, out attempts, out remaining); ViewBag.expanded = expanded; ViewBag.qualified = qualified; ViewBag.thresholds = thresholds; ViewBag.remaining = remaining; ViewBag.attempts = attempts; } catch (Exception exc) { ViewBag.error = exc.Message; } } ViewBag.elapsedSeconds = (DateTime.Now - start).TotalSeconds; return(View()); }
public void TestReconstructSecret() { //assign var secret = "12345678"; var secretbytes = Encoding.UTF8.GetBytes(secret.ToCharArray()); var benaloh = new BenalohLeichter(); var access = new AccessStructure("p1^p2^p3,p2^p3^p4,p1^p3^p4,p1^p2^p4"); var tryIntersect = true; //arrange var optimisedAccess = ThresholdHelper.OptimiseAccessStructure(access, tryIntersect); var shares = benaloh.DivideSecret(secretbytes, access); foreach (var item in shares) { var reconSecret = Encoding.UTF8.GetString(benaloh.ReconstructSecret(item)); Assert.AreEqual(secret, reconSecret, "secret and reconstructed secret are not the same"); } //assert Assert.IsNotNull(shares); Assert.IsTrue(shares.Count > 0); }
public void TestDetectThreshold() { var access = new AccessStructure("p1^p2^p3,p2^p3^p4,p1^p3^p4,p1^p2^p4"); var tryIntersect = true; //arrange var optimisedAccess = ThresholdHelper.OptimiseAccessStructure(access, tryIntersect); Assert.IsTrue(optimisedAccess.ToString() == "Threshold(3,4)[(P1∧P2∧P3∧P4)]"); }
public void IsThresholdShareShorterTestFail() { //assign var nothresholdAccess = "P1^P2,P2^P3,P3^p4,p4^p5,p5^p6,p6^p7,p7^p8,p8^p1"; var tryIntersect = true; //arrange AccessStructure a = new AccessStructure(nothresholdAccess); var thresholds = new List <ThresholdSubset>(); var remaining = new List <QualifiedSubset>(); ThresholdHelper.DetectThresholds(a, tryIntersect, out thresholds, out remaining); bool isEfficicent = ThresholdHelper.IsThresholdShareShorter(a, thresholds, remaining); //assert Assert.IsFalse(isEfficicent); }
public void IsThresholdShareShorterTestPass() { //assign var nothresholdAccess = "p1^p2^p3,p2^p3^p4,p1^p3^p4,p1^p2^p4,p4^p5^p6,p4^p5^p7,p4^p6^p7"; var tryIntersect = true; //arrange AccessStructure a = new AccessStructure(nothresholdAccess); var thresholds = new List <ThresholdSubset>(); var remaining = new List <QualifiedSubset>(); ThresholdHelper.DetectThresholds(a, tryIntersect, out thresholds, out remaining); bool isEfficicent = ThresholdHelper.IsThresholdShareShorter(a, thresholds, remaining); //assert Assert.IsTrue(isEfficicent); }
public void TestDivideSecret() { //assign var secret = "12345678"; var secretbytes = Encoding.UTF8.GetBytes(secret.ToCharArray()); var benaloh = new BenalohLeichter(); var access = new AccessStructure("p1^p2^p3,p2^p3^p4,p1^p3^p4,p1^p2^p4"); var tryIntersect = true; //arrange var optimisedAccess = ThresholdHelper.OptimiseAccessStructure(access, tryIntersect); var shares = benaloh.DivideSecret(secretbytes, optimisedAccess); //assert Assert.IsNotNull(shares); Assert.IsTrue(shares.Count > 0); }
private int wrappedShareLengthDivideSecret(AccessStructure access, bool optimise, bool tryIntersect, string secret, ref List <Int64> elapsedTicks, ref AccessStructure optimisedAccess) { //return new List<IShareCollection>(); optimisedAccess = null; var benaloh = new BenalohLeichter(); var sw = new Stopwatch(); var secretbytes = Encoding.UTF8.GetBytes(secret.ToCharArray()); sw.Start(); if (optimise) { access = ThresholdHelper.OptimiseAccessStructure(access, tryIntersect); optimisedAccess = access; } var shares = getMockShares(access); //benaloh.DivideSecret(secretbytes, access); sw.Stop(); elapsedTicks.Add(sw.ElapsedTicks); return(shares); }