Ejemplo n.º 1
0
        internal Polynomial(GaloisField256 gfield, int[] coefficients)
        {
            int coefficientsLength = coefficients.Length;

            if (coefficientsLength == 0 || coefficients == null)
            {
                throw new ArithmeticException("Can not create empty Polynomial");
            }

            m_GField = gfield;

            m_primitive = gfield.Primitive;

            if (coefficientsLength > 1 && coefficients[0] == 0)
            {
                int firstNonZeroIndex = 1;
                while (firstNonZeroIndex < coefficientsLength && coefficients[firstNonZeroIndex] == 0)
                {
                    firstNonZeroIndex++;
                }

                if (firstNonZeroIndex == coefficientsLength)
                {
                    m_Coefficients = new int[] { 0 }
                }
                ;
                else
                {
                    int newLength = coefficientsLength - firstNonZeroIndex;
                    m_Coefficients = new int[newLength];
                    Array.Copy(coefficients, firstNonZeroIndex, m_Coefficients, 0, newLength);
                }
            }
            else
            {
                m_Coefficients = new int[coefficientsLength];
                Array.Copy(coefficients, m_Coefficients, coefficientsLength);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// After create GeneratorPolynomial. Keep it as long as possible.
 /// Unless QRCode encode is done or no more QRCode need to generate.
 /// </summary>
 internal GeneratorPolynomial(GaloisField256 gfield)
 {
     m_gfield         = gfield;
     m_cacheGenerator = new List <Polynomial>(10);
     m_cacheGenerator.Add(new Polynomial(m_gfield, new int[] { 1 }));
 }