Exemple #1
0
        public virtual bool[][] CalQrcode(byte[] qrcodeData)
        {
            int index1  = 0;
            int length1 = qrcodeData.Length;

            int[]   data = new int[length1 + 32];
            sbyte[] bits = new sbyte[length1 + 32];
            if (length1 <= 0)
            {
                return new bool[1][] { new bool[1] }
            }
            ;
            if (this.qrcodeStructureappendN > 1)
            {
                data[0] = 3;

                bits[0] = (sbyte)4;
                data[1] = this.qrcodeStructureappendM - 1;
                bits[1] = (sbyte)4;
                data[2] = this.qrcodeStructureappendN - 1;
                bits[2] = (sbyte)4;
                data[3] = this.qrcodeStructureappendParity;
                bits[3] = (sbyte)8;
                index1  = 4;
            }
            bits[index1] = (sbyte)4;
            int[] numArray1;
            int   index2;
            int   index3;

            switch (this.qrcodeEncodeMode)
            {
            case QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC:
                numArray1 = new int[41]
                {
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4
                };
                data[index1] = 2;
                int index4 = index1 + 1;
                data[index4] = length1;
                bits[index4] = (sbyte)9;
                index2       = index4;
                int index5 = index4 + 1;
                for (int index6 = 0; index6 < length1; ++index6)
                {
                    char  ch  = (char)qrcodeData[index6];
                    sbyte num = 0;
                    if ((int)ch >= 48 && (int)ch < 58)
                    {
                        num = (sbyte)((int)ch - 48);
                    }
                    else if ((int)ch >= 65 && (int)ch < 91)
                    {
                        num = (sbyte)((int)ch - 55);
                    }
                    else
                    {
                        if ((int)ch == 32)
                        {
                            num = (sbyte)36;
                        }
                        if ((int)ch == 36)
                        {
                            num = (sbyte)37;
                        }
                        if ((int)ch == 37)
                        {
                            num = (sbyte)38;
                        }
                        if ((int)ch == 42)
                        {
                            num = (sbyte)39;
                        }
                        if ((int)ch == 43)
                        {
                            num = (sbyte)40;
                        }
                        if ((int)ch == 45)
                        {
                            num = (sbyte)41;
                        }
                        if ((int)ch == 46)
                        {
                            num = (sbyte)42;
                        }
                        if ((int)ch == 47)
                        {
                            num = (sbyte)43;
                        }
                        if ((int)ch == 58)
                        {
                            num = (sbyte)44;
                        }
                    }
                    if (index6 % 2 == 0)
                    {
                        data[index5] = (int)num;
                        bits[index5] = (sbyte)6;
                    }
                    else
                    {
                        data[index5] = data[index5] * 45 + (int)num;
                        bits[index5] = (sbyte)11;
                        if (index6 < length1 - 1)
                        {
                            ++index5;
                        }
                    }
                }
                index3 = index5 + 1;
                break;

            case QRCodeEncoder.ENCODE_MODE.NUMERIC:
                numArray1 = new int[41]
                {
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    2,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4,
                    4
                };
                data[index1] = 1;
                int index7 = index1 + 1;
                data[index7] = length1;
                bits[index7] = (sbyte)10;
                index2       = index7;
                int index8 = index7 + 1;
                for (int index6 = 0; index6 < length1; ++index6)
                {
                    if (index6 % 3 == 0)
                    {
                        data[index8] = (int)qrcodeData[index6] - 48;
                        bits[index8] = (sbyte)4;
                    }
                    else
                    {
                        data[index8] = data[index8] * 10 + ((int)qrcodeData[index6] - 48);
                        if (index6 % 3 == 1)
                        {
                            bits[index8] = (sbyte)7;
                        }
                        else
                        {
                            bits[index8] = (sbyte)10;
                            if (index6 < length1 - 1)
                            {
                                ++index8;
                            }
                        }
                    }
                }
                index3 = index8 + 1;
                break;

            default:
                numArray1 = new int[41]
                {
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8,
                    8
                };
                data[index1] = 4;
                int index9 = index1 + 1;
                data[index9] = length1;
                bits[index9] = (sbyte)8;
                index2       = index9;
                int num1 = index9 + 1;
                for (int index6 = 0; index6 < length1; ++index6)
                {
                    data[index6 + num1] = (int)qrcodeData[index6] & (int)byte.MaxValue;
                    bits[index6 + num1] = (sbyte)8;
                }
                index3 = num1 + length1;
                break;
            }
            int num2 = 0;

            for (int index6 = 0; index6 < index3; ++index6)
            {
                num2 += (int)bits[index6];
            }
            int index10;

            switch (this.qrcodeErrorCorrect)
            {
            case QRCodeEncoder.ERROR_CORRECTION.L:
                index10 = 1;
                break;

            case QRCodeEncoder.ERROR_CORRECTION.Q:
                index10 = 3;
                break;

            case QRCodeEncoder.ERROR_CORRECTION.H:
                index10 = 2;
                break;

            default:
                index10 = 0;
                break;
            }
            int[][] numArray2 = new int[4][]
            {
                new int[41]
                {
                    0,
                    128,
                    224,
                    352,
                    512,
                    688,
                    864,
                    992,
                    1232,
                    1456,
                    1728,
                    2032,
                    2320,
                    2672,
                    2920,
                    3320,
                    3624,
                    4056,
                    4504,
                    5016,
                    5352,
                    5712,
                    6256,
                    6880,
                    7312,
                    8000,
                    8496,
                    9024,
                    9544,
                    10136,
                    10984,
                    11640,
                    12328,
                    13048,
                    13800,
                    14496,
                    15312,
                    15936,
                    16816,
                    17728,
                    18672
                },
                new int[41]
                {
                    0,
                    152,
                    272,
                    440,
                    640,
                    864,
                    1088,
                    1248,
                    1552,
                    1856,
                    2192,
                    2592,
                    2960,
                    3424,
                    3688,
                    4184,
                    4712,
                    5176,
                    5768,
                    6360,
                    6888,
                    7456,
                    8048,
                    8752,
                    9392,
                    10208,
                    10960,
                    11744,
                    12248,
                    13048,
                    13880,
                    14744,
                    15640,
                    16568,
                    17528,
                    18448,
                    19472,
                    20528,
                    21616,
                    22496,
                    23648
                },
                new int[41]
                {
                    0,
                    72,
                    128,
                    208,
                    288,
                    368,
                    480,
                    528,
                    688,
                    800,
                    976,
                    1120,
                    1264,
                    1440,
                    1576,
                    1784,
                    2024,
                    2264,
                    2504,
                    2728,
                    3080,
                    3248,
                    3536,
                    3712,
                    4112,
                    4304,
                    4768,
                    5024,
                    5288,
                    5608,
                    5960,
                    6344,
                    6760,
                    7208,
                    7688,
                    7888,
                    8432,
                    8768,
                    9136,
                    9776,
                    10208
                },
                new int[41]
                {
                    0,
                    104,
                    176,
                    272,
                    384,
                    496,
                    608,
                    704,
                    880,
                    1056,
                    1232,
                    1440,
                    1648,
                    1952,
                    2088,
                    2360,
                    2600,
                    2936,
                    3176,
                    3560,
                    3880,
                    4096,
                    4544,
                    4912,
                    5312,
                    5744,
                    6032,
                    6464,
                    6968,
                    7288,
                    7880,
                    8264,
                    8920,
                    9368,
                    9848,
                    10288,
                    10832,
                    11408,
                    12016,
                    12656,
                    13328
                }
            };
            int num3 = 0;

            if (this.qrcodeVersion == 0)
            {
                this.qrcodeVersion = 1;
                for (int index6 = 1; index6 <= 40; ++index6)
                {
                    if (numArray2[index10][index6] >= num2 + numArray1[this.qrcodeVersion])
                    {
                        num3 = numArray2[index10][index6];
                        break;
                    }
                    ++this.qrcodeVersion;
                }
            }
            else
            {
                num3 = numArray2[index10][this.qrcodeVersion];
            }
            int num4 = num2 + numArray1[this.qrcodeVersion];

            bits[index2] = (sbyte)((int)bits[index2] + numArray1[this.qrcodeVersion]);
            int maxCodewords = new int[41]
            {
                0,
                26,
                44,
                70,
                100,
                134,
                172,
                196,
                242,
                292,
                346,
                404,
                466,
                532,
                581,
                655,
                733,
                815,
                901,
                991,
                1085,
                1156,
                1258,
                1364,
                1474,
                1588,
                1706,
                1828,
                1921,
                2051,
                2185,
                2323,
                2465,
                2611,
                2761,
                2876,
                3034,
                3196,
                3362,
                3532,
                3706
            }[this.qrcodeVersion];
            int num5 = 17 + (this.qrcodeVersion << 2);

            int[] numArray3 = new int[41]
            {
                0,
                0,
                7,
                7,
                7,
                7,
                7,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                3,
                3,
                3,
                3,
                3,
                3,
                3,
                4,
                4,
                4,
                4,
                4,
                4,
                4,
                3,
                3,
                3,
                3,
                3,
                3,
                3,
                0,
                0,
                0,
                0,
                0,
                0
            };
            int length2 = numArray3[this.qrcodeVersion] + (maxCodewords << 3);

            sbyte[] target1 = new sbyte[length2];
            sbyte[] target2 = new sbyte[length2];
            sbyte[] target3 = new sbyte[length2];
            sbyte[] target4 = new sbyte[15];
            sbyte[] target5 = new sbyte[15];
            sbyte[] target6 = new sbyte[1];
            sbyte[] target7 = new sbyte[128];
            try
            {
                Stream         embeddedFile   = QRCodeEncoder.GetEmbeddedFile(QRCodeEncoder.DATA_PATH + ".qrv" + Convert.ToString(this.qrcodeVersion) + "_" + Convert.ToString(index10) + ".dat");
                BufferedStream bufferedStream = new BufferedStream(embeddedFile);
                SystemUtils.ReadInput((Stream)bufferedStream, target1, 0, target1.Length);
                SystemUtils.ReadInput((Stream)bufferedStream, target2, 0, target2.Length);
                SystemUtils.ReadInput((Stream)bufferedStream, target3, 0, target3.Length);
                SystemUtils.ReadInput((Stream)bufferedStream, target4, 0, target4.Length);
                SystemUtils.ReadInput((Stream)bufferedStream, target5, 0, target5.Length);
                SystemUtils.ReadInput((Stream)bufferedStream, target6, 0, target6.Length);
                SystemUtils.ReadInput((Stream)bufferedStream, target7, 0, target7.Length);
                bufferedStream.Close();
                embeddedFile.Close();
            }
            catch (Exception ex)
            {
                SystemUtils.WriteStackTrace(ex, Console.Error);
            }
            sbyte num6 = 1;

            for (byte index6 = 1; (int)index6 < 128; ++index6)
            {
                if ((int)target7[(int)index6] == 0)
                {
                    num6 = (sbyte)index6;
                    break;
                }
            }
            sbyte[] rsBlockOrder = new sbyte[(int)num6];
            Array.Copy((Array)target7, 0, (Array)rsBlockOrder, 0, (int)(byte)num6);
            sbyte[] numArray4 = new sbyte[15]
            {
                (sbyte)0,
                (sbyte)1,
                (sbyte)2,
                (sbyte)3,
                (sbyte)4,
                (sbyte)5,
                (sbyte)7,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8
            };
            sbyte[] numArray5 = new sbyte[15]
            {
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)8,
                (sbyte)7,
                (sbyte)5,
                (sbyte)4,
                (sbyte)3,
                (sbyte)2,
                (sbyte)1,
                (sbyte)0
            };
            int maxDataCodewords = num3 >> 3;
            int length3          = 4 * this.qrcodeVersion + 17;

            sbyte[] target8 = new sbyte[length3 * length3 + length3];
            try
            {
                Stream         embeddedFile   = QRCodeEncoder.GetEmbeddedFile(QRCodeEncoder.DATA_PATH + ".qrvfr" + Convert.ToString(this.qrcodeVersion) + ".dat");
                BufferedStream bufferedStream = new BufferedStream(embeddedFile);
                SystemUtils.ReadInput((Stream)bufferedStream, target8, 0, target8.Length);
                bufferedStream.Close();
                embeddedFile.Close();
            }
            catch (Exception ex)
            {
                SystemUtils.WriteStackTrace(ex, Console.Error);
            }
            if (num4 <= num3 - 4)
            {
                data[index3] = 0;
                bits[index3] = (sbyte)4;
            }
            else if (num4 < num3)
            {
                data[index3] = 0;
                bits[index3] = (sbyte)(num3 - num4);
            }
            else if (num4 > num3)
            {
                Console.Out.WriteLine("overflow");
            }
            sbyte[]   rsecc         = QRCodeEncoder.CalculateRSECC(QRCodeEncoder.DivideDataBy8Bits(data, bits, maxDataCodewords), target6[0], rsBlockOrder, maxDataCodewords, maxCodewords);
            sbyte[][] matrixContent = new sbyte[length3][];
            for (int index6 = 0; index6 < length3; ++index6)
            {
                matrixContent[index6] = new sbyte[length3];
            }
            for (int index6 = 0; index6 < length3; ++index6)
            {
                for (int index11 = 0; index11 < length3; ++index11)
                {
                    matrixContent[index11][index6] = (sbyte)0;
                }
            }
            for (int index6 = 0; index6 < maxCodewords; ++index6)
            {
                sbyte num7 = rsecc[index6];
                for (int index11 = 7; index11 >= 0; --index11)
                {
                    int index12 = index6 * 8 + index11;
                    matrixContent[(int)target1[index12] & (int)byte.MaxValue][(int)target2[index12] & (int)byte.MaxValue] = (sbyte)((int)byte.MaxValue * ((int)num7 & 1) ^ (int)target3[index12]);
                    num7 = (sbyte)SystemUtils.URShift((int)num7 & (int)byte.MaxValue, 1);
                }
            }
            for (int index6 = numArray3[this.qrcodeVersion]; index6 > 0; --index6)
            {
                int index11 = index6 + maxCodewords * 8 - 1;
                matrixContent[(int)target1[index11] & (int)byte.MaxValue][(int)target2[index11] & (int)byte.MaxValue] = (sbyte)((int)byte.MaxValue ^ (int)target3[index11]);
            }
            sbyte num8  = QRCodeEncoder.SelectMask(matrixContent, numArray3[this.qrcodeVersion] + maxCodewords * 8);
            sbyte num9  = (sbyte)(1 << (int)num8);
            sbyte num10 = (sbyte)(index10 << 3 | (int)(byte)num8);

            string[] strArray = new string[32]
            {
                "101010000010010",
                "101000100100101",
                "101111001111100",
                "101101101001011",
                "100010111111001",
                "100000011001110",
                "100111110010111",
                "100101010100000",
                "111011111000100",
                "111001011110011",
                "111110110101010",
                "111100010011101",
                "110011000101111",
                "110001100011000",
                "110110001000001",
                "110100101110110",
                "001011010001001",
                "001001110111110",
                "001110011100111",
                "001100111010000",
                "000011101100010",
                "000001001010101",
                "000110100001100",
                "000100000111011",
                "011010101011111",
                "011000001101000",
                "011111100110001",
                "011101000000110",
                "010010010110100",
                "010000110000011",
                "010111011011010",
                "010101111101101"
            };
            for (int startIndex = 0; startIndex < 15; ++startIndex)
            {
                sbyte num7 = sbyte.Parse(strArray[(int)num10].Substring(startIndex, startIndex + 1 - startIndex));
                matrixContent[(int)numArray4[startIndex] & (int)byte.MaxValue][(int)numArray5[startIndex] & (int)byte.MaxValue] = (sbyte)((int)num7 * (int)byte.MaxValue);
                matrixContent[(int)target4[startIndex] & (int)byte.MaxValue][(int)target5[startIndex] & (int)byte.MaxValue]     = (sbyte)((int)num7 * (int)byte.MaxValue);
            }
            bool[][] flagArray = new bool[length3][];
            for (int index6 = 0; index6 < length3; ++index6)
            {
                flagArray[index6] = new bool[length3];
            }
            int index13 = 0;

            for (int index6 = 0; index6 < length3; ++index6)
            {
                for (int index11 = 0; index11 < length3; ++index11)
                {
                    int num7 = ((int)matrixContent[index11][index6] & (int)num9) != 0 ? 0 : ((int)target8[index13] != 49 ? 1 : 0);
                    flagArray[index11][index6] = num7 == 0;
                    ++index13;
                }
                ++index13;
            }
            return(flagArray);
        }