DOCX

The generation of qr code details and principle

By Jerry Cox,2015-02-20 17:50
17 views 0
The generation of qr code details and principle

    The generation of qr code details and

    principle

    QR Code also called QR Code, QR for the Quick Response, is a mobile devices in recent years very popular a kind of coding way, it is better than the traditional Bar Code Bar Code can save more information, can also be said more data types: such as characters, Numbers, Japanese, Chinese, and so on.This two days to learn about qr code image generated by the details, feel this thing is a cryptographic algorithm, in this writing a, this article revealed.For studious people learn.

    On the QR Code Specification, can see the

    PDF:http://raidenii.net/files/datasheets/misc/qr_code.pdf

    Basic knowledge of

    First of all, we say the first 40 a qr code size.The official Version Version.Version 1 is 21 x 21 matrix, Version 2 is 25 x 25 matrix, the size of the Version 3 is 29, each adding a Version, will increase the size of the 4, the formula is: (n - 1) * 4 + 21 highest Version is the Version number (V), 40 (40-1) * 4 + 21 = 177, so the highest is 177 x 177 square.

    Here we see a qr code sample:

Positioning design

    ; The Position Detection Pattern is positioning design, used for

    rectangular size mark qr code.The three positioning pattern has a

    white border called Separators for Postion Detection Patterns.The

    three rather than four means can identify a rectangle.

    ; Timing is used to locate Patterns.Because of qr code there are 40

    kinds of size, size too big after line needs to have a root, or else

    could sweep the slanting when scanning.

    ; Alignment Patterns (including Version2) Version 2 above only the

    qr code need to the east, also is to locate.

    The functional data

    ; The Format Information exists in all sizes, used to hold some

    formatting data.

    ; The Version Information above > = Version 7, need to reserve two

    pieces of 3 x 6 area to store some Version Information. Data code and error correction code

    ; In addition to the above those places, the rest of the place to store

    the Data Code Data Code and the Error Correction Code Error

    Correction Code.

    Data encoding

    Let's say data encoding.QR code to support the following code:

    Numeric mode digital coding, from 0 to 9.For encoding digital number is not a multiple of 3, then, the last remaining 1 or 2 digits will be transformed into 4 or 7 bits, the other is 10,12,14 every 3 digit bits, into how much to look at the size of the qr code below (Table 3 shows that there is a Table)

    Alphanumeric mode character encoding.Including 0-9, the capital of A to Z (no lowercase), as well as the symbolic $% * + - / : including Spaces.These characters will be mapped to a character index table.As shown below: (the SP is a space, Char is character, the Value is the process of the index Value) coding are the two groups, the characters in the two and then switch to the table below 45 into the system, and then into 11 bits of binary, if finally there is a single, then into 6 bits of binary.And coding mode and the number of characters need according to the different size Version into 9, 11 or 13 binary (Table 3) in the following Table

    Byte mode, the Byte code, can be a scale of 0-255 to ISO - 8859-1 characters.Some of the qr code scanner can automatically detect whether the utf-8 encoding.

    Kanji mode it is Japanese, and double byte code.Also, can also be used in Chinese code.Japanese and Chinese character coding will subtract a value.Such as: character in the 0 x8140 to 0 x9ffc minus 8140, at 0 xe040 character xebbf xc140 minus 0 0, then the results before take out two hexadecimal times 0 xc0, then add two hexadecimal, after finally to 13 bit coding.The diagram below sample:

    Extended Channel Interpretation (ECI) mode is mainly used for particular character set.Not all of the scanner is supported by the code.

    Structured Append mode used in hybrid coding, that is to say, the qr code contains a variety of encoding format.

    FNC1 mode this encoding is mainly for some special industries or industry.Such as GS1 bar code, etc.

    Simplicity, behind three not discussed in this article.

    The following two tables,

    ; Table 2 is the coding Format of the "number", this thing to write

    in the Format Information.Note: Chinese is 1101

    ; Table 3 shows, different versions (size) of qr code, for, Numbers,

    characters, bytes and Kanji mode, for a single encoding two

    hexadecimal digits.(in the specifications of qr code, there are all

    kinds of coding specification table, behind also mentioned)

    We see a few examples below,

    Example 1: digital coding

    Under the size of the Version 1, the error correction level for H, code: 01234567

    1. Put the Numbers into three groups: 012 345 67

    2. Put them into a binary: 012 to 0000001100;345 to 0101011001;67 to 1000011.

    3. The three binary string: 0000001100 0101011001 1000011

    4. Put the number of Numbers to binary (version 1 - H is 10 bits) : binary eight Numbers is 0000001000

    5. The digital coding symbol code added to the front in 0001 and step 4:0001 0000001000 0000001100 0101011001 1000011

    Example 2: a character encoding

    Under the size of the Version 1, the error correction level for H, under the condition of coding: AC - 42

    1. Found in the character index table AC - 42 of these five note index (10,12,41,4,2)

    2. The two groups: (10, 12) (41, 4) and (2)

    3. Each group into 11 binary bits:

    (10, 12) 10 * 45 + 12 equal to 462 to 462

    (4) 41 41 * 45 + 4 equal to 1849 to 1849

    (2) is equal to 2 to 000010

    4. Connect the binary: 00111001110 11100111001 000010

    5. Put the number of characters converted to binary (Version 1 - H for 9 bits) : five characters, 5 to 000000101

    6. On his head and coding identification number code: 0010 and 5 0010 000000101 00111001110 11100111001 000010

    Terminator and JiFu

    If we have a string of HELLO WORLD to coding, according to the example above two, we can get the following code,

    coding Number of characters HELLO WORLD coding

    0010 000001011 01100001011 01111000110 1

    0001011100 10110111000 10

    011010100 01111000110

    We add terminator:

    coding Number of characHELLO WORLD codiThe end of the

    ters ng

    0010 000001011 01100001011 0111100000

    00110 10001011100

    10110111000 100110

    10100 01111000110

    According to the eight bits rearrangement

    If add up all the coding is not eight times we need to add enough in the behind of 0, such as a total of 78 bits above, so, we add 2 0, then according to the eight bits in good group:

    00100000 01011011 00001011 01111000 11010001 01110010 11011100 01001101 11010001 010000, 00

    Swallow the code (Padding Bytes)

    Finally, if haven't reached the limitation of our greatest number of bits, we need to add some filling yards (Padding Bytes), Padding Bytes is to repeat the following two Bytes: 11101100, 00010001 (the two binary to decimal is 236 and 17, I don't know why, just know that's what I put the Spec) about each Version of the biggest bits each error correction level limit, seeQR Code Spec28 pages to the Table on page 32-7 a Table.

    Suppose we need level error correction coding is Version 1 Q, so, its biggest need 104 bits, and we only 80 bits above, so, also need to fill 24 bits, that is need 3 Padding Bytes, we will add three, we get the following code:

    00100000 01011011 00001011 01111000 11010001 01110010 11011100 01001101 01110010 01000000 11101100 00010001 11101100

    The code above is the Data code, called Data Codewords, each of the eight bits is called a codeword, we have the Data code and error correction information.

    Error correction code

    We said to the above some Level of Error Correction, the Error Correction Code Level, there are four levels of Error Correction in the qr Code, which is why qr Code it can sweep out damaged, is why some people join icon in the center of the qr Code.

    Error correction capacity

    L levels 7% of the word can be fixed

    M 15% of the word can be fixed

    Q level 25% of the word can be fixed

    H level 30% of the word can be fixed

    QR, then, is how the data code and error correction code?First, we need to for grouping data code, which is divided into different blocks, and then for each Block error correction code, how to group, we can look atQR Code SpecPage 33 to page 44 of the Table - 13 to the Table - 22 the definition of the Table.Note that the last two columns:

    ; Number of Error Code Correction Blocks: need how many pieces.

    ; The Error Correction Code Per Blocks: every piece of Code number,

    the number of so-called Code, that is how many bytes of 8 bits.

    For example: the Version of the error correction level 5 + Q: need four Blocks (2 Blocks as a group, a total of two sets), the head of a group of two Blocks in each 15 bits data + 9 bits ecc (note: the codewords in the table is a 8 bits of byte) (note: in the last case (c, k, r) of the formula is: c = k + 2 * r, because after the footnote explains: the capacity of the error correcting code is less than half of the error correcting code)

    Examples below give a five - Q (as binary would read to form is too big, so I can use the decimal system, we can see each piece of ecc has 18 codewords, namely 18 8 bits of binary number)

    group block data For each block e

    rror correction

    code

    1 1 38 67 85 70 134 85 45, 115, 213, 199,

    85 194 119 103 6 18 11, 247, 241, 22

     m 38 3, 229, 248, 154,

    117, 154, 111, 86,

     161, 111, 39

    2 7, 246, 246, 66, 7,60, 202, 182, 124,

     118, 134, 242, 38, 87, 204, 96, 157,

     86 22, 198, 199, 1 200, 134, 27, 12

    46 (6) 9, 209, 17, 163, 1

    63, 120, 133

    2 1 50 7 182 230 247 11148 116 177 212 11

    9 118 134 87 82 6 16 133 75 242 238 1

    34 151 50 38 7 77 195 230 189 108

     240 192 141

    2 70 247 118 86 247 6235 159 5 173 24 1

     118 50 16 236 17 247 59 106 40, 255,

    36 17 236 17, 236 172, 82, 2 255 32

     33, 178, 236

    Note: the error correcting code mainly through qr codeReed-Solomon error correction(reed Solomon error correction algorithm).To this algorithm, for me is very complicated, there are a lot of math, such as: polynomial division, the number 1-255 mapping into 2 n (0 < = n < = 255) of the Galois Field Galois Field, such as god, and the error correction based on the basic mathematical formula, because of my poor data base, is too complicated for me, so I didn't understand, for a while and also in learning, so, I am here is not to say these things.Also please forgive me.(of course, if you have very understand, your friends are numerous consult teach me)

    The final code

    By placing

    If you think we canstart to draw, you are wrong.Chaos in the qr code technology hasn't gone, it will bring the data code and error correction code all the codewords alternate put together.How to alternate, rules are as follows:

    For data code: first put every piece of codewords out and sorted by compliance first, and then take the first block of the second and so on.Such as the Data in the example above Codewords are as follows: B68718381156 16 13

    l7 5 0 37 8 5 910 8 08

    o4 4 9 3

    c

    k

1

    B2267 1127 3821116 l446 1348 6 2 994o6 6 8 4 2 8 9 6 c

    k

2

    B122157 118386 1157 l83410 137 8 2 350 o2 0 7 9 8 4 4 1 c

    k

3

    B721816 1512121212l0 416 950 6 37 37 37 3o7 8 4 1 6 6 6 6 c

    k

4

    Let's pick up the first column: 67, 246, 182, 70

    Then take the second column: 67, 246, 182, 70, 85246230, 247

    So on: 67, 67, 246, 70, 85246230,

    85246230..................38,6,50,17,7,236

    For error correcting code, as well as:

    B211412222211118113l191 5 14422451516 619 o3 9 5 7 1 3 9 8 4 7 4 1 1 1 c

    k

1

    B829621112121211111l7 06 0 0825037 207 6623

Report this document

For any questions or suggestions please email
cust-service@docsford.com