Exemplo n.º 1
0
        /// <summary>GF multiplication</summary>
        /// <param name="other">the other GF-poly</param>
        /// <returns>new GF-poly obtained by multiplying this  with other</returns>
        internal iText.Barcodes.Qrcode.GF256Poly Multiply(iText.Barcodes.Qrcode.GF256Poly other)
        {
            if (!field.Equals(other.field))
            {
                throw new ArgumentException("GF256Polys do not have same GF256 field");
            }
            if (IsZero() || other.IsZero())
            {
                return(field.GetZero());
            }
            int[] aCoefficients = this.coefficients;
            int   aLength       = aCoefficients.Length;

            int[] bCoefficients = other.coefficients;
            int   bLength       = bCoefficients.Length;

            int[] product = new int[aLength + bLength - 1];
            for (int i = 0; i < aLength; i++)
            {
                int aCoeff = aCoefficients[i];
                for (int j = 0; j < bLength; j++)
                {
                    product[i + j] = GF256.AddOrSubtract(product[i + j], field.Multiply(aCoeff, bCoefficients[j]));
                }
            }
            return(new iText.Barcodes.Qrcode.GF256Poly(field, product));
        }
Exemplo n.º 2
0
        internal iText.Barcodes.Qrcode.GF256Poly[] Divide(iText.Barcodes.Qrcode.GF256Poly other)
        {
            if (!field.Equals(other.field))
            {
                throw new ArgumentException("GF256Polys do not have same GF256 field");
            }
            if (other.IsZero())
            {
                throw new ArgumentException("Divide by 0");
            }
            iText.Barcodes.Qrcode.GF256Poly quotient  = field.GetZero();
            iText.Barcodes.Qrcode.GF256Poly remainder = this;
            int denominatorLeadingTerm        = other.GetCoefficient(other.GetDegree());
            int inverseDenominatorLeadingTerm = field.Inverse(denominatorLeadingTerm);

            while (remainder.GetDegree() >= other.GetDegree() && !remainder.IsZero())
            {
                int degreeDifference = remainder.GetDegree() - other.GetDegree();
                int scale            = field.Multiply(remainder.GetCoefficient(remainder.GetDegree()), inverseDenominatorLeadingTerm);
                iText.Barcodes.Qrcode.GF256Poly term = other.MultiplyByMonomial(degreeDifference, scale);
                iText.Barcodes.Qrcode.GF256Poly iterationQuotient = field.BuildMonomial(degreeDifference, scale);
                quotient  = quotient.AddOrSubtract(iterationQuotient);
                remainder = remainder.AddOrSubtract(term);
            }
            return(new iText.Barcodes.Qrcode.GF256Poly[] { quotient, remainder });
        }
Exemplo n.º 3
0
        /// <summary>GF addition or subtraction (they are identical for a GF(2^n)</summary>
        /// <param name="other">the other GF-poly</param>
        /// <returns>new GF256Poly obtained by summing this GF and other</returns>
        internal iText.Barcodes.Qrcode.GF256Poly AddOrSubtract(iText.Barcodes.Qrcode.GF256Poly other)
        {
            if (!field.Equals(other.field))
            {
                throw new ArgumentException("GF256Polys do not have same GF256 field");
            }
            if (IsZero())
            {
                return(other);
            }
            if (other.IsZero())
            {
                return(this);
            }
            int[] smallerCoefficients = this.coefficients;
            int[] largerCoefficients  = other.coefficients;
            if (smallerCoefficients.Length > largerCoefficients.Length)
            {
                int[] temp = smallerCoefficients;
                smallerCoefficients = largerCoefficients;
                largerCoefficients  = temp;
            }
            int[] sumDiff    = new int[largerCoefficients.Length];
            int   lengthDiff = largerCoefficients.Length - smallerCoefficients.Length;

            // Copy high-order terms only found in higher-degree polynomial's coefficients
            Array.Copy(largerCoefficients, 0, sumDiff, 0, lengthDiff);
            for (int i = lengthDiff; i < largerCoefficients.Length; i++)
            {
                sumDiff[i] = GF256.AddOrSubtract(smallerCoefficients[i - lengthDiff], largerCoefficients[i]);
            }
            return(new iText.Barcodes.Qrcode.GF256Poly(field, sumDiff));
        }