示例#1
0
        public Polynomial Mod(Polynomial e)
        {
            if (GetLength() - e.GetLength() < 0) {
            return this;
            }

            int ratio = QRMath.Glog(Get(0)) - QRMath.Glog(e.Get(0));
            int[] num = new int[GetLength()];
            for (int i = 0; i < GetLength(); i++) {
            num[i] = Get(i);
            }

            for (int i = 0; i < e.GetLength(); i++) {
            num[i] ^= QRMath.Gexp(QRMath.Glog(e.Get(i)) + ratio);
            }

            return new Polynomial(num).Mod(e);
        }
示例#2
0
        public Polynomial Mod(Polynomial e)
        {
            if (this.GetLength() - e.GetLength() < 0)
            {
                return(this);
            }
            int num = QRMath.Glog(this.Get(0)) - QRMath.Glog(e.Get(0));

            int[] array = new int[this.GetLength()];
            for (int i = 0; i < this.GetLength(); i++)
            {
                array[i] = this.Get(i);
            }
            for (int j = 0; j < e.GetLength(); j++)
            {
                array[j] ^= QRMath.Gexp(QRMath.Glog(e.Get(j)) + num);
            }
            return(new Polynomial(array).Mod(e));
        }
示例#3
0
        public Polynomial Mod(Polynomial e)
        {
            if (GetLength() - e.GetLength() < 0)
            {
                return(this);
            }

            int ratio = QRMath.Glog(Get(0)) - QRMath.Glog(e.Get(0));

            int[] num = new int[GetLength()];
            for (int i = 0; i < GetLength(); i++)
            {
                num[i] = Get(i);
            }

            for (int i = 0; i < e.GetLength(); i++)
            {
                num[i] ^= QRMath.Gexp(QRMath.Glog(e.Get(i)) + ratio);
            }

            return(new Polynomial(num).Mod(e));
        }
示例#4
0
        public Polynomial Multiply(Polynomial e)
        {
            int[] num = new int[GetLength() + e.GetLength() - 1];
            for (int i = 0; i < GetLength(); i++)
            {
                for (int j = 0; j < e.GetLength(); j++)
                {
                    num[i + j] ^= QRMath.Gexp(QRMath.Glog(Get(i)) + QRMath.Glog(e.Get(j)));
                }
            }

            return(new Polynomial(num));
        }
示例#5
0
        private static byte[] CreateBytes(BitBuffer buffer, RSBlock[] rsBlocks)
        {
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            int[][] array  = new int[rsBlocks.Length][];
            int[][] array2 = new int[rsBlocks.Length][];
            for (int i = 0; i < rsBlocks.Length; i++)
            {
                int dataCount = rsBlocks[i].GetDataCount();
                int num4      = rsBlocks[i].GetTotalCount() - dataCount;
                num2     = Math.Max(num2, dataCount);
                num3     = Math.Max(num3, num4);
                array[i] = new int[dataCount];
                for (int j = 0; j < array[i].Length; j++)
                {
                    array[i][j] = (int)(255 & buffer.GetBuffer()[j + num]);
                }
                num += dataCount;
                Polynomial errorCorrectPolynomial = QRUtil.GetErrorCorrectPolynomial(num4);
                Polynomial polynomial             = new Polynomial(array[i], errorCorrectPolynomial.GetLength() - 1);
                Polynomial polynomial2            = polynomial.Mod(errorCorrectPolynomial);
                array2[i] = new int[errorCorrectPolynomial.GetLength() - 1];
                for (int k = 0; k < array2[i].Length; k++)
                {
                    int num5 = k + polynomial2.GetLength() - array2[i].Length;
                    array2[i][k] = ((num5 >= 0) ? polynomial2.Get(num5) : 0);
                }
            }
            int num6 = 0;

            for (int l = 0; l < rsBlocks.Length; l++)
            {
                num6 += rsBlocks[l].GetTotalCount();
            }
            byte[] array3 = new byte[num6];
            int    num7   = 0;

            for (int m = 0; m < num2; m++)
            {
                for (int n = 0; n < rsBlocks.Length; n++)
                {
                    if (m < array[n].Length)
                    {
                        array3[num7++] = (byte)array[n][m];
                    }
                }
            }
            for (int num8 = 0; num8 < num3; num8++)
            {
                for (int num9 = 0; num9 < rsBlocks.Length; num9++)
                {
                    if (num8 < array2[num9].Length)
                    {
                        array3[num7++] = (byte)array2[num9][num8];
                    }
                }
            }
            return(array3);
        }
示例#6
0
        public Polynomial Multiply(Polynomial e)
        {
            int[] num = new int[GetLength() + e.GetLength() - 1];
            for (int i = 0; i < GetLength(); i++) {
            for (int j = 0; j < e.GetLength(); j++) {
                num[i + j] ^= QRMath.Gexp(QRMath.Glog(Get(i)) + QRMath.Glog(e.Get(j)));
            }
            }

            return new Polynomial(num);
        }
示例#7
0
        private static byte[] CreateBytes(BitBuffer buffer, RSBlock[] rsBlocks)
        {
            int offset     = 0;
            int maxDcCount = 0;
            int maxEcCount = 0;

            int[][] dcdata = new int[rsBlocks.Length][];
            int[][] ecdata = new int[rsBlocks.Length][];

            for (int r = 0; r < rsBlocks.Length; r++)
            {
                int dcCount = rsBlocks[r].GetDataCount();
                int ecCount = rsBlocks[r].GetTotalCount() - dcCount;

                maxDcCount = Math.Max(maxDcCount, dcCount);
                maxEcCount = Math.Max(maxEcCount, ecCount);

                dcdata[r] = new int[dcCount];
                for (int i = 0; i < dcdata[r].Length; i++)
                {
                    dcdata[r][i] = 0xff & buffer.GetBuffer()[i + offset];
                }
                offset += dcCount;

                Polynomial rsPoly  = QRUtil.GetErrorCorrectPolynomial(ecCount);
                Polynomial rawPoly = new Polynomial(dcdata[r], rsPoly.GetLength() - 1);

                Polynomial modPoly = rawPoly.Mod(rsPoly);
                ecdata[r] = new int[rsPoly.GetLength() - 1];
                for (int i = 0; i < ecdata[r].Length; i++)
                {
                    int modIndex = i + modPoly.GetLength() - ecdata[r].Length;
                    ecdata[r][i] = (modIndex >= 0)? modPoly.Get(modIndex) : 0;
                }
            }

            int totalCodeCount = 0;

            for (int i = 0; i < rsBlocks.Length; i++)
            {
                totalCodeCount += rsBlocks[i].GetTotalCount();
            }

            byte[] data  = new byte[totalCodeCount];
            int    index = 0;

            for (int i = 0; i < maxDcCount; i++)
            {
                for (int r = 0; r < rsBlocks.Length; r++)
                {
                    if (i < dcdata[r].Length)
                    {
                        data[index++] = (byte)dcdata[r][i];
                    }
                }
            }

            for (int i = 0; i < maxEcCount; i++)
            {
                for (int r = 0; r < rsBlocks.Length; r++)
                {
                    if (i < ecdata[r].Length)
                    {
                        data[index++] = (byte)ecdata[r][i];
                    }
                }
            }

            return(data);
        }
示例#8
0
 public Polynomial Multiply(Polynomial e)
 {
     int[] array = new int[this.GetLength() + e.GetLength() - 1];
     for (int i = 0; i < this.GetLength(); i++)
     {
         for (int j = 0; j < e.GetLength(); j++)
         {
             array[i + j] ^= QRMath.Gexp(QRMath.Glog(this.Get(i)) + QRMath.Glog(e.Get(j)));
         }
     }
     return(new Polynomial(array));
 }