예제 #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);
            }
        }
예제 #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)
     {
         new Polynomial(M_gfield, new int[] { 1 })
     };
 }
예제 #3
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);
            }
        }
예제 #4
0
        internal Polynomial(GaloisField256 gfield, int[] coefficients)
        {
            int coefficientsLength = coefficients.Length;

            if (coefficientsLength == 0 || coefficients is null)
            {
                throw new ArithmeticException($"Cannot create empty {nameof(Polynomial)}.");
            }

            GField = gfield;

            Primitive = gfield.Primitive;

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

                if (firstNonZeroIndex == coefficientsLength)
                {
                    Coefficients = new int[] { 0 };
                }
                else
                {
                    int newLength = coefficientsLength - firstNonZeroIndex;
                    Coefficients = new int[newLength];
                    Array.Copy(coefficients, firstNonZeroIndex, Coefficients, 0, newLength);
                }
            }
            else
            {
                Coefficients = new int[coefficientsLength];
                Array.Copy(coefficients, Coefficients, coefficientsLength);
            }
        }
예제 #5
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 }));
 }
예제 #6
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}));
		}