Exemple #1
0
        internal GenericGFPoly[] divide(GenericGFPoly other)
        {
            if (!field.Equals(other.field))
            {
                throw new ArgumentException("GenericGFPolys do not have same GenericGF field");
            }
            if (other.isZero)
            {
                throw new ArgumentException("Divide by 0", "other");
            }

            GenericGFPoly quotient  = new GenericGFPoly(field, new int[] { 0 }, encoding);
            GenericGFPoly remainder = this;

            int denominatorLeadingTerm        = other.getCoefficient(other.Degree);
            int inverseDenominatorLeadingTerm = field.inverse(denominatorLeadingTerm);

            while (remainder.Degree >= other.Degree && !remainder.isZero)
            {
                int           degreeDifference  = remainder.Degree - other.Degree;
                int           scale             = field.multiply(remainder.getCoefficient(remainder.Degree), inverseDenominatorLeadingTerm);
                GenericGFPoly term              = other.multiplyByMonomial(degreeDifference, scale);
                GenericGFPoly iterationQuotient = buildMonomial(degreeDifference, scale);
                quotient  = quotient.addOrSubtract(iterationQuotient);
                remainder = remainder.addOrSubtract(term);
            }

            return(new GenericGFPoly[] { quotient, remainder });
        }
Exemple #2
0
        // Method added by Sonic-The-Hedgehog-LNK1123 (github.com/Sonic-The-Hedgehog-LNK1123)
        // this method replaces original method "runEuclideanAlgorithm"
        internal GenericGFPoly runBerlekampMasseyAlgorithm(GenericGFPoly syndrome, int erasureCount)
        {
            GenericGFPoly sigma = new GenericGFPoly(field, new int[] { 1 }, false);
            GenericGFPoly old   = new GenericGFPoly(field, new int[] { 1 }, false);

            for (int i = 0; i < (syndrome.Coefficients.Length - erasureCount); i++)
            {
                int delta = syndrome.getCoefficient(i);
                for (int j = 1; j < sigma.Coefficients.Length; j++)
                {
                    delta ^= field.multiply(sigma.getCoefficient(j), syndrome.getCoefficient(i - j));
                }

                List <int> oldList = new List <int>(old.Coefficients);
                oldList.Add(0);
                old = new GenericGFPoly(field, oldList.ToArray(), false);

                if (delta != 0)
                {
                    if (old.Coefficients.Length > sigma.Coefficients.Length)
                    {
                        GenericGFPoly new_loc = old.multiply(delta);
                        old   = sigma.multiply(field.inverse(delta));
                        sigma = new_loc;
                    }

                    sigma = sigma.addOrSubtract(old.multiply(delta));
                }
            }

            List <int> sigmaList = new List <int>(sigma.Coefficients);

            while (Convert.ToBoolean(sigmaList.Count) && sigmaList[0] == 0)
            {
                sigmaList.RemoveAt(0);
            }

            sigma = new GenericGFPoly(field, sigmaList.ToArray(), false);

            return(sigma);
        }