public void BDVerifierSerializationTest()
        {
            VerifierBitDecompositionParameters verifier = new VerifierBitDecompositionParameters(
                _parameters[0].G, _parameters[0].Generators, _parameters[0]);

            string jsonString = CryptoSerializer.Serialize <VerifierBitDecompositionParameters>(verifier);
            VerifierBitDecompositionParameters deserializedVerifier = CryptoSerializer.Deserialize <VerifierBitDecompositionParameters>(jsonString);

            Assert.AreEqual(verifier.Group.GroupName, deserializedVerifier.Group.GroupName);
            StaticHelperClass.AssertArraysAreEqual(verifier.PublicValues, deserializedVerifier.PublicValues, "PublicValues");
            StaticHelperClass.AssertArraysAreEqual <DLRepOfGroupElement>(verifier.Witnesses, deserializedVerifier.Witnesses, "Witnesses");
        }
        public void BDEndToEnd()
        {
            FieldZqElement     bigNum       = _parameters[0].FieldZq.GetElement(2056);
            PedersenCommitment bigNumCommit = new PedersenCommitment(bigNum, _parameters[0]);
            int decompositionLength         = 15;


            ProverBitDecompositionParameters proverParams = new ProverBitDecompositionParameters(
                bigNumCommit,
                decompositionLength,
                _parameters[0]);

            BitDecompositionProof proof = new BitDecompositionProof(proverParams);

            Assert.IsTrue(proof.Verify(proverParams), "could not verify proof with prover params");

            VerifierBitDecompositionParameters verifierParams = new VerifierBitDecompositionParameters(
                proverParams.ClosedCommitment,
                proverParams.ClosedBitDecomposition(),
                proverParams);

            Assert.IsTrue(proof.Verify(verifierParams), "could not verify proof with verifier parameters");
        }
        public void BDDecompositionTest()
        {
            FieldZqElement zero;
            FieldZqElement one;
            FieldZqElement two;
            FieldZqElement five;
            FieldZqElement ten;
            BitArray       dec;
            FieldZqElement recompose;

            for (int paramIndex = 0; paramIndex < _parameters.Length; ++paramIndex)
            {
                FieldZq field = _parameters[paramIndex].FieldZq;
                zero = field.Zero;
                one  = field.One;
                two  = field.GetElement(2);
                five = field.GetElement(5);
                ten  = field.GetElement(10);

                dec       = VerifierBitDecompositionParameters.GetBitDecomposition(one, 10, field);
                recompose = VerifierBitDecompositionParameters.GetBitComposition(dec, field);
                Assert.AreEqual(one, recompose);
                Assert.AreEqual(true, dec.Get(0), "first bit should be one");
                Assert.AreEqual(false, dec.Get(1), "second  bit should be zero");
                Assert.AreEqual(10, dec.Length, "decomposition length should be 10");

                dec       = VerifierBitDecompositionParameters.GetBitDecomposition(two, 20, field);
                recompose = VerifierBitDecompositionParameters.GetBitComposition(dec, field);
                Assert.AreEqual(20, dec.Length, "decomposition length should be 10");
                Assert.AreEqual(two, recompose);
                Assert.AreEqual(false, dec[0], "first bit is 0");
                Assert.AreEqual(true, dec[1], "second bit is 1");
                Assert.AreEqual(false, dec[2], "third bit is 0");
                Assert.AreEqual(false, dec[19], "last bit is 0");

                dec       = VerifierBitDecompositionParameters.GetBitDecomposition(five, 30, field);
                recompose = VerifierBitDecompositionParameters.GetBitComposition(dec, field);
                Assert.AreEqual(30, dec.Length, "decomposition length should be 30");
                Assert.AreEqual(five, recompose);
                Assert.AreEqual(true, dec[0], "first bit is 1");
                Assert.AreEqual(false, dec[1], "second bit is 0");
                Assert.AreEqual(true, dec[2], "third bit is 1");
                Assert.AreEqual(false, dec[3], "fourth bit is 0");
                Assert.AreEqual(false, dec[4], "fifth bit is 0");
                Assert.AreEqual(false, dec[29], "last bit is 0");

                dec       = VerifierBitDecompositionParameters.GetBitDecomposition(ten, 30, field);
                recompose = VerifierBitDecompositionParameters.GetBitComposition(dec, field);
                Assert.AreEqual(30, dec.Length, "decomposition length should be 30");
                Assert.AreEqual(ten, recompose);
                Assert.AreEqual(false, dec[0], "first bit is 0");
                Assert.AreEqual(true, dec[1], "second bit is 1");
                Assert.AreEqual(false, dec[2], "third bit is 0");
                Assert.AreEqual(true, dec[3], "fourth bit is 1");
                Assert.AreEqual(false, dec[4], "fifth bit is 0");
                Assert.AreEqual(false, dec[29], "last bit is 0");


                FieldZqElement random = field.GetRandomElement(true);
                dec       = VerifierBitDecompositionParameters.GetBitDecomposition(random, 0, field);
                recompose = VerifierBitDecompositionParameters.GetBitComposition(dec, field);
                Assert.AreEqual(random, recompose, "recomposition failed");
            }
        }