示例#1
0
        public void T05_PolynomialMultiplication()
        {
            GF2pField      field = new GF2pField(8);
            GF2pPolynomial a = new GF2pPolynomial(field, 0, 4, 17, 0, 9), b = new GF2pPolynomial(field, 19, 11, 0, 100);

            Assert.AreEqual(new GF2pPolynomial(field, 0, 76, 18, 187, 6, 57, 0, 99), a * b);
            Assert.AreEqual(a * b, b * a);
            Assert.AreEqual(new GF2pPolynomial(field, 0), new GF2pPolynomial(field, 0) * a);
            Assert.AreEqual(new GF2pPolynomial(field, 0), default(GF2pPolynomial) * b);

            Assert.AreEqual(new GF2pPolynomial(field, 121, 49, 0, 33), b * 7);

            Assert.AreEqual(0, GF2pPolynomial.MultiplyAt(a, b, 0));
            Assert.AreEqual(76, GF2pPolynomial.MultiplyAt(a, b, 1));
            Assert.AreEqual(18, GF2pPolynomial.MultiplyAt(a, b, 2));
            Assert.AreEqual(187, GF2pPolynomial.MultiplyAt(a, b, 3));
            Assert.AreEqual(6, GF2pPolynomial.MultiplyAt(a, b, 4));
            Assert.AreEqual(57, GF2pPolynomial.MultiplyAt(a, b, 5));
            Assert.AreEqual(0, GF2pPolynomial.MultiplyAt(a, b, 6));
            Assert.AreEqual(99, GF2pPolynomial.MultiplyAt(a, b, 7));
            Assert.AreEqual(0, GF2pPolynomial.MultiplyAt(a, b, 8));
            Assert.AreEqual(0, GF2pPolynomial.MultiplyAt(a, b, 9));

            Assert.AreEqual(0, a.MultiplyAt(b, 0));
            Assert.AreEqual(76, a.MultiplyAt(b, 1));
            Assert.AreEqual(18, a.MultiplyAt(b, 2));
            Assert.AreEqual(187, a.MultiplyAt(b, 3));
        }
        static void BerlekampMassey(GF2pPolynomial syndromes, GF2pPolynomial erasureLocator, GF2pPolynomial erasureEvaluator, int erasureCount,
                                    out GF2pPolynomial errataLocator, out GF2pPolynomial errataEvaluator)
        {
            GF2pPolynomial locator, prevLocator, evaluator, prevEvaluator, a, b;

            if (erasureCount != 0)
            {
                locator = erasureLocator;
                a       = evaluator = erasureEvaluator;
            }
            else
            {
                evaluator = locator = new GF2pPolynomial(syndromes.Field, 1);
                a         = new GF2pPolynomial(syndromes.Field, 0);
            }
            b = locator;

            int L = 0;

            for (int i = 0, count = syndromes.Length - erasureCount; i < count; i++)
            {
                int k = i + erasureCount, delta = GF2pPolynomial.MultiplyAt(syndromes, locator, k);
                prevLocator   = locator;
                prevEvaluator = evaluator;
                GF2pPolynomial shiftA = a << 1, shiftB = b << 1;
                locator   += shiftB * delta;
                evaluator += shiftA * delta;
                if (delta == 0 || 2 * L > k + erasureCount + 1)
                {
                    b = shiftB;
                    a = shiftA;
                }
                else
                {
                    b = prevLocator / delta;
                    a = prevEvaluator / delta;
                    L = k + 1 - L;
                }
            }

            if (evaluator.Length > locator.Length)
            {
                evaluator = evaluator.Truncate(locator.Length);
            }
            evaluator = CalculateErrorEvaluator(syndromes, locator);

            errataLocator   = locator;
            errataEvaluator = evaluator;
        }