示例#1
0
        /// <summary>
        /// データブロックを返します。
        /// </summary>
        private Byte[][] BuildDataBlock()
        {
            byte[] dataBytes = GetMessageBytes();

            int numPreBlocks = RSBlock.GetTotalNumber(
                _parent.ErrorCorrectionLevel, _currVersion, true);
            int numFolBlocks = RSBlock.GetTotalNumber(
                _parent.ErrorCorrectionLevel, _currVersion, false);

            byte[][] ret = new byte[numPreBlocks + numFolBlocks][];

            int numPreBlockDataCodewords = RSBlock.GetNumberDataCodewords(
                _parent.ErrorCorrectionLevel, _currVersion, true);
            int index = 0;

            for (int i = 0; i < numPreBlocks; ++i)
            {
                byte[] data = new byte[numPreBlockDataCodewords];
                Array.Copy(dataBytes, index, data, 0, data.Length);
                index += data.Length;
                ret[i] = data;
            }

            int numFolBlockDataCodewords = RSBlock.GetNumberDataCodewords(
                _parent.ErrorCorrectionLevel, _currVersion, false);

            for (int i = numPreBlocks; i < numPreBlocks + numFolBlocks; ++i)
            {
                byte[] data = new byte[numFolBlockDataCodewords];
                Array.Copy(dataBytes, index, data, 0, data.Length);
                index += data.Length;
                ret[i] = data;
            }
            return(ret);
        }
示例#2
0
        /// <summary>
        /// 誤り訂正データ領域のブロックを生成します。
        /// </summary>
        /// <param name="dataBlock">データ領域のブロック</param>
        private byte[][] BuildErrorCorrectionBlock(byte[][] dataBlock)
        {
            int numECCodewords = RSBlock.GetNumberECCodewords(
                _parent.ErrorCorrectionLevel, _currVersion);
            int numPreBlocks = RSBlock.GetTotalNumber(
                _parent.ErrorCorrectionLevel, _currVersion, true);
            int numFolBlocks = RSBlock.GetTotalNumber(
                _parent.ErrorCorrectionLevel, _currVersion, false);

            byte[][] ret = new byte[numPreBlocks + numFolBlocks][];

            for (int i = 0; i < ret.Length; ++i)
            {
                ret[i] = new byte[numECCodewords];
            }

            int[] gp = GeneratorPolynomials.Item(numECCodewords);

            for (int blockIndex = 0; blockIndex < dataBlock.Length; ++blockIndex)
            {
                int   size     = dataBlock[blockIndex].Length + ret[blockIndex].Length;
                int[] data     = new int[size];
                int   eccIndex = data.Length - 1;

                for (int i = 0; i < dataBlock[blockIndex].Length; ++i)
                {
                    data[eccIndex] = dataBlock[blockIndex][i];
                    eccIndex--;
                }

                for (int i = data.Length - 1; i >= numECCodewords; --i)
                {
                    if (data[i] > 0)
                    {
                        int exp = GaloisField256.ToExp(data[i]);
                        eccIndex = i;

                        for (int j = gp.Length - 1; j >= 0; --j)
                        {
                            data[eccIndex] ^= GaloisField256.ToInt((gp[j] + exp) % 255);
                            eccIndex--;
                        }
                    }
                }

                eccIndex = numECCodewords - 1;

                for (int i = 0; i < ret[blockIndex].Length; ++i)
                {
                    ret[blockIndex][i] = (byte)data[eccIndex];
                    eccIndex--;
                }
            }
            return(ret);
        }