Пример #1
0
        protected override Zp GetRecombinedResult(IList <Zp> recvList, int prime)
        {
            // Scan recvList - if there are null elements replace them arbitrarily to Zp with zero value
            for (int i = 0; i < recvList.Count; i++)
            {
                if (recvList[i] == null)
                {
                    recvList[i] = new Zp(prime, 0);
                }
            }

            var xVlaues = new List <Zp>();
            int w       = NumTheoryUtils.GetFieldMinimumPrimitive(prime);

            for (int i = 0; i < recvList.Count; i++)
            {
                xVlaues.Add(new Zp(prime, NumTheoryUtils.ModPow(w, i, prime)));
            }

            // Should call Welch-Berlekamp Decoder to fix error at last stage
            var fixedShares = WelchBerlekampDecoder.Decode(xVlaues, recvList, PolynomialDeg, PolynomialDeg, prime);

            if (fixedShares == null)
            {
                throw new Exception("There were more then polynomialDegree = " + PolynomialDeg + " Cheaters - cannot extract results.");
            }

            return(ShamirSharing.Recombine(fixedShares, PolynomialDeg, prime, true));
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Started.");
            StaticRandom.Init(seed);

            int quorumSize = 20;
            int degree     = quorumSize / 3;

            var secret      = new Zp(Prime, 3);
            var shareMatrix = ZpMatrix.GetIdentityMatrix(quorumSize, Prime);

            // create the initial shares
            var initalShares = ShamirSharing.Share(secret, quorumSize, degree);

            for (var i = 0; i < quorumSize; i++)
            {
                IList <Zp> reshares = QuorumSharing.CreateReshares(initalShares[i], quorumSize, degree);

                for (var j = 0; j < quorumSize; j++)
                {
                    shareMatrix.SetMatrixCell(j, i, reshares[j]);
                }
            }

            // combine the reshares
            List <Zp> finalShares = new List <Zp>();

            for (var i = 0; i < quorumSize; i++)
            {
                Zp finalShare = QuorumSharing.CombineReshares(shareMatrix.GetMatrixRow(i), quorumSize, Prime);
                finalShares.Add(finalShare);
            }

            // combine the shares
            Zp final = ShamirSharing.Recombine(finalShares, degree, Prime);

            Console.WriteLine(final.Value);
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Пример #3
0
 // TODO: Mahdi: Should this method be virtual?
 protected virtual Zp GetRecombinedResult(IList <Zp> recvList, int prime)
 {
     return(ShamirSharing.Recombine(recvList, PolynomialDeg, prime));
 }