private int[] FindErrorLocations(GenericGfPoly errorLocator)
        {
            int numErrors = errorLocator.Degree;

            if (numErrors == 1)
            {
                return(new[] { errorLocator.GetCoefficient(1) });
            }
            int[] result = new int[numErrors];
            int   e      = 0;

            for (int i = 1; i < field.Size && e < numErrors; i++)
            {
                if (errorLocator.EvaluateAt(i) == 0)
                {
                    result[e] = field.Inverse(i);
                    e++;
                }
            }
            if (e != numErrors)
            {
                return(null);
            }
            return(result);
        }
        internal GenericGfPoly[] RunEuclideanAlgorithm(GenericGfPoly a, GenericGfPoly b, int R)
        {
            if (a.Degree < b.Degree)
            {
                GenericGfPoly temp = a;
                a = b;
                b = temp;
            }

            GenericGfPoly rLast = a;
            GenericGfPoly r     = b;
            GenericGfPoly tLast = field.Zero;
            GenericGfPoly t     = field.One;

            while (r.Degree >= R / 2)
            {
                GenericGfPoly rLastLast = rLast;
                GenericGfPoly tLastLast = tLast;
                rLast = r;
                tLast = t;

                if (rLast.IsZero)
                {
                    return(null);
                }
                r = rLastLast;
                GenericGfPoly q = field.Zero;
                int           denominatorLeadingTerm = rLast.GetCoefficient(rLast.Degree);
                int           dltInverse             = field.Inverse(denominatorLeadingTerm);
                while (r.Degree >= rLast.Degree && !r.IsZero)
                {
                    int degreeDiff = r.Degree - rLast.Degree;
                    int scale      = field.Multiply(r.GetCoefficient(r.Degree), dltInverse);
                    q = q.AddOrSubtract(field.BuildMonomial(degreeDiff, scale));
                    r = r.AddOrSubtract(rLast.MultiplyByMonomial(degreeDiff, scale));
                }

                t = q.Multiply(tLast).AddOrSubtract(tLastLast);

                if (r.Degree >= rLast.Degree)
                {
                    return(null);
                }
            }

            int sigmaTildeAtZero = t.GetCoefficient(0);

            if (sigmaTildeAtZero == 0)
            {
                return(null);
            }

            int           inverse = field.Inverse(sigmaTildeAtZero);
            GenericGfPoly sigma   = t.Multiply(inverse);
            GenericGfPoly omega   = r.Multiply(inverse);

            return(new[] { sigma, omega });
        }