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);
        }
Пример #2
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 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);
        }
Пример #4
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);
        }