Ejemplo n.º 1
0
        public QRPolynomial Multiply(QRPolynomial e)
        {
            var num = new DataCache(this.GetLength() + e.GetLength() - 1);

            for (int i = 0; i < this.GetLength(); i++)
            {
                for (int j = 0; j < e.GetLength(); j++)
                {
                    num[i + j] ^= QRMath.GExp(QRMath.GLog(this.Get(i)) + QRMath.GLog(e.Get(j)));
                }
            }

            return(new QRPolynomial(num, 0));
        }
Ejemplo n.º 2
0
        public QRPolynomial Mod(QRPolynomial e)
        {
            if (Convert.ToInt64(this.GetLength()) - Convert.ToInt64(e.GetLength()) < 0)
            {
                return(this);
            }

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

            var num = new DataCache(this.GetLength());

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

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

            // recursive call
            return(new QRPolynomial(num, 0).Mod(e));
        }
Ejemplo n.º 3
0
        private DataCache CreateBytes(QRBitBuffer buffer, List <QRRSBlock> rsBlocks)
        {
            int offset = 0;

            int maxDcCount = 0;
            int maxEcCount = 0;

            var dcdata = new DataCache[(rsBlocks.Count)];
            var ecdata = new DataCache[(rsBlocks.Count)];

            for (int r = 0; r < rsBlocks.Count; r++)
            {
                int dcCount = rsBlocks[(int)r].DataCount;
                int ecCount = rsBlocks[(int)r].TotalCount - dcCount;

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

                dcdata[r] = new DataCache(dcCount);

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

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

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

            int totalCodeCount = 0;

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

            var data  = new DataCache(totalCodeCount);
            int index = 0;

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

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

            return(data);
        }