Пример #1
0
        public void TestPolynomial_Eval()
        {
            var p = HashiCorpShamir.MakePolynomial(42, 1);

            Assert.Equal(42, p.Evaluate(0));

            // out := p.evaluate(1)
            // exp := add(42, mult(1, p.coefficients[1]))
            // if out != exp {
            //     t.Fatalf("bad: %v %v %v", out, exp, p.coefficients)
            // }

            var ret = p.Evaluate(1);
            var exp = HashiCorpShamir.Add(42,
                                          HashiCorpShamir.Mult(1, p.Coefficients[1]));

            Assert.Equal(ret, exp);
        }
Пример #2
0
        public void TestInterpolate_Rand()
        {
            for (int i = 0; i < 256; i++)
            {
                var p = HashiCorpShamir.MakePolynomial((byte)i, 2);

                var x_vals = new byte[] { 1, 2, 3 };
                var y_vals = new byte[] { p.Evaluate(1), p.Evaluate(2), p.Evaluate(3) };

                // out := interpolatePolynomial(x_vals, y_vals, 0)
                // if out != uint8(i) {
                //     t.Fatalf("Bad: %v %d", out, i)
                // }

                Assert.Equal((byte)i,
                             HashiCorpShamir.InterpolatePolynomial(x_vals, y_vals, 0));
            }
        }
Пример #3
0
        public void TestPolynomial_Random()
        {
            var p = HashiCorpShamir.MakePolynomial(42, 2);

            Assert.Equal(42, p.Coefficients[0]);
        }