Example #1
0
        private static int[] PolynomialDevision(ErrorCorrectionLvl ErrCorr, int version, int[] FullDataInts)
        {
            int ErrCorrectionCodewordsCount;

            int[]      MessagePolynomial;
            AlphaPow[] GeneratorPolinomial;
            int        DevisionSteps;

            int[] GeneratorPolinomialInt;
            int[] XORresult;
            ErrCorrectionCodewordsCount = ErrorCorrectionTable.GetErrorCorrectionCodewordsPerBlock(ErrCorr, version);
            MessagePolynomial           = FullDataInts;
            GeneratorPolinomial         = Helper.generatePolinomial(ErrCorrectionCodewordsCount);

            Array.Reverse(GeneratorPolinomial);
            DevisionSteps = MessagePolynomial.Length;            //
            int[] mult = new int[ErrCorrectionCodewordsCount];   //DevisionSteps->ErrCorrectionCodewordsCount
            MessagePolynomial = Helper.joinArrs <int> (MessagePolynomial, mult);
            AlphaPow[] mult1 = new AlphaPow[MessagePolynomial.Length - GeneratorPolinomial.Length];
            for (int i = 0; i < mult1.Length; i++)
            {
                mult1[i] = new AlphaPow(-1, false);
            }
            GeneratorPolinomial    = Helper.joinArrs <AlphaPow> (GeneratorPolinomial, mult1);
            GeneratorPolinomialInt = new int[GeneratorPolinomial.Length];
            bool[][] Codewords = new bool[DevisionSteps][];

            //first step
            AlphaPow[] GenPolRes = new AlphaPow[GeneratorPolinomial.Length];
            Array.Copy(GeneratorPolinomial, GenPolRes, GeneratorPolinomial.Length);
            for (int j = 0; j < GeneratorPolinomial.Length; j++)
            {
                if (GenPolRes[j].pow == -1)
                {
                    GeneratorPolinomialInt[j] = 0;
                }
                else
                {
                    AlphaPow a = new AlphaPow(AlphaPow.getPow(MessagePolynomial[0]), false);
                    GenPolRes[j] *= a;
                    GeneratorPolinomialInt[j] = GenPolRes[j].getInt();
                    //GeneratorPolinomial[j] = new AlphaPow( AlphaPow.getPow( GeneratorPolinomialInt[j] ^ MessagePolynomial[j]),false);
                }
            }
            XORresult = new int[GeneratorPolinomial.Length];
            for (int j = 0; j < GeneratorPolinomial.Length; j++)
            {
                XORresult[j] = GeneratorPolinomialInt[j] ^ MessagePolynomial[j];
            }

            if (XORresult[0] == 0)
            {
                int[] tempIntArr = new int[XORresult.Length - 1];
                Array.Copy(XORresult, 1, tempIntArr, 0, tempIntArr.Length);
                XORresult = new int[tempIntArr.Length];
                Array.Copy(tempIntArr, XORresult, tempIntArr.Length);
            }
            AlphaPow[] tempArr = new AlphaPow[GeneratorPolinomial.Length - 1];
            Array.Copy(GeneratorPolinomial, 0, tempArr, 0, GeneratorPolinomial.Length - 1);
            GeneratorPolinomial = new AlphaPow[tempArr.Length];
            Array.Copy(tempArr, GeneratorPolinomial, tempArr.Length);
            //////////////////


            bool[][] DataCodewords = new bool[DevisionSteps][];
            DataCodewords[0] = new bool[8];
            bool[] tempT = Encode.Binary(
                XORresult[0]);

            for (int up = 0; up < 8; up++)
            {
                DataCodewords[0][up] = tempT[up];
            }
            Array.Copy(tempT, DataCodewords[0], 8);

            for (int i = 1; i < DevisionSteps; i++)
            {
                DataCodewords[i] = new bool[8];
                //Array.Copy(Encoder.Binary(XORresult[0]), DataCodewords[i], 8);
                for (int up = 0; up < 8; up++)
                {
                    DataCodewords[0][up] = Encode.Binary(XORresult[0])[up];
                }
                Array.Copy(GeneratorPolinomial, GenPolRes, GeneratorPolinomial.Length);
                for (int j = 0; j < GeneratorPolinomial.Length; j++)
                {
                    if (GenPolRes[j].pow == -1)
                    {
                        GeneratorPolinomialInt[j] = 0;
                    }
                    else
                    {
                        AlphaPow a = new AlphaPow(AlphaPow.getPow(XORresult[0]), false);
                        GenPolRes[j] *= a;
                        GeneratorPolinomialInt[j] = GenPolRes[j].getInt();
                        //GeneratorPolinomial[j] = new AlphaPow( AlphaPow.getPow( GeneratorPolinomialInt[j] ^ MessagePolynomial[j]),false);
                    }
                }
                int[] XORtemp = new int[XORresult.Length];
                Array.Copy(XORresult, XORtemp, XORresult.Length);
                XORresult = new int[GeneratorPolinomial.Length];

                for (int j = 0; j < GeneratorPolinomial.Length; j++)
                {
                    XORresult[j] = GeneratorPolinomialInt[j] ^ XORtemp[j];
                }

                if (XORresult[0] == 0)
                {
                    int[] tempIntArr = new int[XORresult.Length - 1];
                    Array.Copy(XORresult, 1, tempIntArr, 0, tempIntArr.Length);
                    XORresult = new int[tempIntArr.Length];
                    Array.Copy(tempIntArr, XORresult, tempIntArr.Length);
                }
                tempArr = new AlphaPow[GeneratorPolinomial.Length - 1];
                Array.Copy(GeneratorPolinomial, 0, tempArr, 0, GeneratorPolinomial.Length - 1);
                GeneratorPolinomial = new AlphaPow[tempArr.Length];
                Array.Copy(tempArr, GeneratorPolinomial, tempArr.Length);
            }

            int size = XORresult.Length;

            //for ( int i = 0 ; i < size ; i++ ) {
            //	if ( XORresult[i] == 0 ) {
            //		int[] Xtemp = new int[i];
            //		Array.Copy ( XORresult , 0 , Xtemp , 0 , i );
            //		XORresult = new int[Xtemp.Length];
            //		Array.Copy ( Xtemp , XORresult , Xtemp.Length );
            //		break;
            //	}
            //}
            //////////////////
            for (int i = size - 1; i >= 0; i--)
            {
                if (XORresult[i] == 0)
                {
                    int[] Xtemp = new int[i];
                    Array.Copy(XORresult, 0, Xtemp, 0, i);
                    XORresult = new int[Xtemp.Length];
                    Array.Copy(Xtemp, XORresult, Xtemp.Length);
                }
                else
                {
                    break;
                }
            }
            return(XORresult);
        }