multiplyByMonomial() private method

private multiplyByMonomial ( int degree, int coefficient ) : GF256Poly
degree int
coefficient int
return GF256Poly
 public void encode(int[] toEncode, int ecBytes)
 {
     if (ecBytes == 0)
     {
         throw new ArgumentException("No error correction bytes");
     }
     int dataBytes = toEncode.Length - ecBytes;
     if (dataBytes <= 0)
     {
         throw new ArgumentException("No data bytes provided");
     }
     GF256Poly generator = buildGenerator(ecBytes);
     var infoCoefficients = new int[dataBytes];
     Array.Copy(toEncode, 0, infoCoefficients, 0, dataBytes);
     var info = new GF256Poly(field, infoCoefficients);
     info = info.multiplyByMonomial(ecBytes, 1);
     GF256Poly remainder = info.divide(generator)[1];
     int[] coefficients = remainder.Coefficients;
     int numZeroCoefficients = ecBytes - coefficients.Length;
     for (int i = 0; i < numZeroCoefficients; i++)
     {
         toEncode[dataBytes + i] = 0;
     }
     Array.Copy(coefficients, 0, toEncode, dataBytes + numZeroCoefficients, coefficients.Length);
 }
示例#2
0
        internal GF256Poly[] divide(GF256Poly other)
        {
            if (!field.Equals(other.field))
            {
                throw new ArgumentException("GF256Polys do not have same GF256 field");
            }
            if (other.Zero)
            {
                throw new ArgumentException("Divide by 0");
            }

            GF256Poly quotient = field.Zero;
            GF256Poly remainder = this;

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

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

            return new[] {quotient, remainder};
        }