예제 #1
0
 public static AlphaPow operator +( AlphaPow p1 , AlphaPow p2 )
 {
     int t1 = getInt ( p1.pow );
     int t2 = getInt ( p2.pow );
     int y = t1 ^ t2;
     AlphaPow a = new AlphaPow ( y , true );
     return a;
 }
예제 #2
0
        public static AlphaPow operator +(AlphaPow p1, AlphaPow p2)
        {
            int      t1 = getInt(p1.pow);
            int      t2 = getInt(p2.pow);
            int      y  = t1 ^ t2;
            AlphaPow a  = new AlphaPow(y, true);

            return(a);
        }
예제 #3
0
 public static AlphaPow[] generatePolinomial(int pow)
 {
     AlphaPow[] ans = new AlphaPow[2];
     ans[0] = new AlphaPow(0, false);
     ans[1] = new AlphaPow(0, false);
     AlphaPow[] bit = new AlphaPow[2];
     bit[1] = new AlphaPow(0, false);
     for (int i = 0; i < pow - 1; i++)
     {
         bit[0] = new AlphaPow(i + 1, false);
         ans    = multiply(ans, bit);
     }
     return(ans);
 }
예제 #4
0
        public static AlphaPow[] multiply(AlphaPow[] p1, AlphaPow[] p2)
        {
            int outSize = (p1.Length - 1) + (p2.Length - 1);

            AlphaPow[] ans = new AlphaPow[outSize + 1];
            for (int i = p1.Length - 1; i > -1; i--)
            {
                for (int j = p2.Length - 1; j > -1; j--)
                {
                    if (ans[i + j] == null)
                    {
                        ans[i + j] = new AlphaPow();
                        ans[i + j] = p1[i] * p2[j];
                    }
                    else
                    {
                        ans[i + j] += p1[i] * p2[j];
                    }
                }
            }
            return(ans);
        }
예제 #5
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);
        }
예제 #6
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;
        }