http://en.m.wikipedia.org
QR codes use Reed–Solomon error correction over the finite field or GF(28), the elements of which are encoded as bytes of 8 bits; the byte with a standard numerical value encodes the field element where is taken to be a primitive element satisfying . The primitive polynomial is , corresponding to the polynomial number 285, with initial root = 0 to obtain generator polynomials.
The Reed–Solomon code uses one of 37 different polynomials over , with degrees ranging from 7 to 68, depending on how many error correction bytes the code adds. It is implied by the form of Reed–Solomon used (systematic BCH view) that these polynomials are all on the form . However, the rules for selecting the degree are specific to the QR standard.
For example, the generator polynomial used for the Version 1 QR code (21×21), when 7 error correction bytes are used, is: .
This is obtained by multiplying the first seven terms: .
The same may also be expressed using decimal coefficients (over ), as: .
The highest power of in the polynomial (the degree , of the polynomial) determines the number of error correction bytes. In this case, the degree is 7.
When discussing the Reed–Solomon code phase there is some risk for confusion, in that the QR ISO/IEC standard uses the term codeword for the elements of , which with respect to the Reed–Solomon code are symbols, whereas it uses the term block for what with respect to the Reed–Solomon code are the codewords. The number of data versus error correction bytes within each block depends on (i) the version (side length) of the QR symbol and (ii) the error correction level, of which there are four. The higher the error correction level, the less storage capacity. The following table lists the approximate error correction capability at each of the four levels:
Level L (Low) | 7% of data bytes can be restored. |
Level M (Medium) | 15% of data bytes can be restored. |
Level Q (Quartile) | 25% of data bytes can be restored. |
Level H (High) | 30% of data bytes can be restored. |
In larger QR symbols, the message is broken up into several Reed–Solomon code blocks. The block size is chosen so that no attempt is made at correcting more than 15 errors per block; this limits the complexity of the decoding algorithm. The code blocks are then interleaved together, making it less likely that localized damage to a QR symbol will overwhelm the capacity of any single block.
The Version 1 QR symbol with level L error correction, for example, consists of a single error correction block with a total of 26 code bytes (made of 19 message bytes and seven error correction bytes). It can correct up to 2 byte errors. Hence, this code is known as a (26,19,2) error correction code over GF(28) . It is also sometimes represented in short, as (26,19) code.
Due to error correction, it is possible to create artistic QR codes with embellishments to make them more readable or attractive to the human eye, and to incorporate colors, logos, and other features into the QR code block; the embellishments are treated as errors, but the codes still scan correctly.
It is also possible to design artistic QR codes without reducing the error correction capacity by manipulating the underlying mathematical constructs. Image processing algorithms are also used to reduce errors in QR-code.
The format information records two things: the error correction level and the mask pattern used for the symbol. Masking is used to break up patterns in the data area that might confuse a scanner, such as large blank areas or misleading features that look like the locator marks. The mask patterns are defined on a grid that is repeated as necessary to cover the whole symbol. Modules corresponding to the dark areas of the mask are inverted. The 5-bit format information is protected from errors with a BCH code, and two complete copies are included in each QR symbol. A (15,5) triple error-correcting BCH code over GF(24) is used, having the generator polynomial . It can correct at most 3 bit-errors out of the 5 data bits. There are a total of 15 bits in this BCH code (10 bits are added for error correction). This 15-bit code is itself X-ORed with a fixed 15-bit mask pattern (101010000010010) to prevent an all-zero string.
To obtain the error correction (EC) bytes for a message "www.wikipedia.org", the following procedure may be carried out:
The message is 17 bytes long, hence it can be encoded using a (26,19,2) Reed-Solomon code to fit in a Ver1 (21×21) symbol, which has a maximum capacity of 19 bytes (for L level error correction).
The generator polynomial specified for the (26,19,2) code, is: , which may also be written in the form of a matrix of decimal coefficients:
[1 127 122 154 164 11 68 117]
The 17-byte long message "www.wikipedia.org" as hexadecimal coefficients (ASCII values), denoted by M1 through M17 is:
[77 77 77 2E 77 69 6B 69 70 65 64 69 61 2E 6F 72 67]
The encoding mode is "Byte encoding". Hence the 'Enc' field is [0100] (4 bits). The length of the above message is 17 bytes hence 'Len' field is [00010001] (8 bits). The 'End' field is End of message marker [0000] (4 bits).
The message code word (without EC bytes) is of the form:
['Enc' 'Len' w w w . w i k i p e d i a . o r g 'End']
Substituting the hexadecimal values, it can be expressed as:
[4 11 77 77 77 2E 77 69 6B 69 70 65 64 69 61 2E 6F 72 67 0]
This is rearranged as 19-byte blocks of 8 bits each:
[41 17 77 77 72 E7 76 96 B6 97 06 56 46 96 12 E6 F7 26 70]
Using the procedure for Reed-Solomon systematic encoding, the 7 EC bytes obtained (E1 through E7, as shown in the symbol) which are the coefficients (in decimal) of the remainder after polynomial division are:
[174 173 239 6 151 143 37]
or in hexadecimal values:
[AE AD EF 06 97 8F 25]
These 7 EC bytes are then appended to the 19-byte message. The resulting coded message has 26 bytes (in hexadecimal):
[41 17 77 77 72 E7 76 96 B6 97 06 56 46 96 12 E6 F7 26 70 AE AD EF 06 97 8F 25]
Note: The bit values shown in the Ver1 QR symbol below do not match with the above values, as the symbol has been masked using a mask pattern (001).
The message dataset is placed from right to left in a zigzag pattern, as shown below. In larger symbols, this is complicated by the presence of the alignment patterns and the use of multiple interleaved error-correction blocks.
The general structure of a QR encoding is as a sequence of 4 bit indicators with payload length dependent on the indicator mode (e.g. byte encoding payload length is dependent on the first byte).
Four-bit indicators are used to select the encoding mode and convey other information.
Encoding modes can be mixed as needed within a QR symbol. (e.g., a url with a long string of alphanumeric characters )
[ Mode Indicator][ Mode bitstream ] --> [ Mode Indicator][ Mode bitstream ] --> etc... --> [ 0000 End of message (Terminator) ]
After every indicator that selects an encoding mode is a length field that tells how many characters are encoded in that mode. The number of bits in the length field depends on the encoding and the symbol version.
Alphanumeric encoding mode stores a message more compactly than the byte mode can, but cannot store lower-case letters and has only a limited selection of punctuation marks, which are sufficient for rudimentary web addresses. Two characters are coded in an 11-bit value by this formula:
This has the exception that the last character in an alphanumeric string with an odd length is read as a 6-bit value instead.
The following images offer more information about the QR code.
Model 1 QR code is an older version of the specification. It is visually similar to the widely seen model 2 codes, but lacks alignment patterns. Differences are in the bottom right corner, and in the midsections of the bottom and right edges are additional functional regions.
Micro QR code is a smaller version of the QR code standard for applications where symbol size is limited. There are four different versions (sizes) of Micro QR codes: the smallest is 11×11 modules; the largest can hold 35 numeric characters, or 21 ASCII alphanumeric characters, or 15 bytes (128 bits).
Rectangular Micro QR Code (also known as rMQR Code) is a two-dimensional (2D) matrix barcode invented and standardized in 2022 by Denso Wave as ISO/IEC 23941. rMQR Code is designed as a rectangular variation of the QR code and has the same parameters and applications as original QR codes; however, rMQR Code is more suitable for rectangular areas, and has a difference between width and height up to 19 in the R7x139 version.
iQR code is an alternative to existing square QR codes developed by Denso Wave. iQR codes can be created in square or rectangular formations; this is intended for situations where a longer and narrower rectangular shape is more suitable, such as on cylindrical objects. iQR codes can fit the same amount of information in 30% less space. There are 61 versions of square iQR codes, and 15 versions of rectangular codes. For squares, the minimum size is 9 × 9 modules; rectangles have a minimum of 19 × 5 modules. iQR codes add error correction level S, which allows for 50% error correction. iQR Codes had not been given an ISO/IEC specification as of 2015, and only proprietary Denso Wave products could create or read iQR codes.
Secure Quick Response (SQR) code is a QR code that contains a "private data" segment after the terminator instead of the specified filler bytes "ec 11". This private data segment must be deciphered with an encryption key. This can be used to store private information and to manage a company's internal information.
Frame QR is a QR code with a "canvas area" that can be flexibly used. In the center of this code is the canvas area, where graphics, letters, and more can be flexibly arranged, making it possible to lay out the code without losing the design of illustrations, photos, etc.
Researchers have proposed a new High Capacity Colored 2-Dimensional (HCC2D) Code, which builds upon a QR code basis for preserving the QR robustness to distortions and uses colors for increasing data density (as of 2014 it is still in the prototyping phase). The HCC2D code specification is described in details in Querini et al. (2011), while techniques for color classification of HCC2D code cells are described in detail in Querini and Italiano (2014), which is an extended version of Querini and Italiano (2013).
Introducing colors into QR codes requires addressing additional issues. In particular, during QR code reading only the brightness information is taken into account, while HCC2D codes have to cope with chromatic distortions during the decoding phase. In order to ensure adaptation to chromatic distortions that arise in each scanned code, HCC2D codes make use of an additional field: the Color Palette Pattern. This is because color cells of a Color Palette Pattern are supposed to be distorted in the same way as color cells of the Encoding Region. Replicated color palettes are used for training machine-learning classifiers.
Accessible QR is a type of QR code that combines a standard QR code with a dot-dash pattern positioned around one corner of the code to provide product information for people who are blind and partially sighted. The codes, announce product categories and product details such as instructions, ingredients, safety warnings, and recycling information. The data is structured for the needs of users who are blind or partially sighted and offers larger text or audio output. It can read QR codes from a metre away, activating the smartphone's accessibility features like VoiceOver to announce product details.
The use of QR code technology is freely licensed as long as users follow the standards for QR code documented with JIS or ISO/IEC. Non-standardized codes may require special licensing.
Denso Wave owns a number of patents on QR code technology, but has chosen to exercise them in a limited fashion. In order to promote widespread usage of the technology Denso Wave chose to waive its rights to a key patent in its possession for standardized codes only. In the US, the granted QR code patent, 5726435, expired on March 14, 2015. In Japan, the corresponding patent, 2938338, expired on March 14, 2014. The European Patent Office granted patent 0672994 to Denso Wave, which was then validated into French, UK, and German patents, all of which expired in March 2015.
The text QR Code itself is a registered trademark and wordmark of Denso Wave Incorporated. In UK, the trademark is registered as E921775, the term QR Code, with a filing date of 3 September 1998. The UK version of the trademark is based on the Kabushiki Kaisha Denso (DENSO CORPORATION) trademark, filed as Trademark 000921775, the term QR Code, on 3 September 1998 and registered on 16 December 1999 with the European Union OHIM (Office for Harmonization in the Internal Market). The U.S. Trademark for the term QR Code is Trademark 2435991 and was filed on 29 September 1998 with an amended registration date of 13 March 2001, assigned to Denso Corporation. In South Korea, trademark application filed on 18 November 2011 was refused at 20 March 2012, because the Korean Intellectual Property Office viewed that the phrase was genericized among South Korean people to refer to matrix barcodes in general.
The only context in which common QR codes can carry executable data is the URL data type. These URLs may host JavaScript code, which can be used to exploit vulnerabilities in applications on the host system, such as the reader, the web browser, or the image viewer, since a reader will typically send the data to the application associated with the data type used by the QR code.
In the case of no software exploits, malicious QR codes combined with a permissive reader can still put a computer's contents and user's privacy at risk. This practice is known as "attagging", a portmanteau of "attack tagging". They are easily created and can be affixed over legitimate QR codes.[failed verification] On a smartphone, the reader's permissions may allow use of the camera, full Internet access, read/write contact data, GPS, read browser history, read/write local storage, and global system changes.[improper synthesis?]
Risks include linking to dangerous web sites with browser exploits, enabling the microphone/camera/GPS, and then streaming those feeds to a remote server, analysis of sensitive data (passwords, files, contacts, transactions), and sending email/SMS/IM messages or packets for DDoS as part of a botnet, corrupting privacy settings, stealing identity, and even containing malicious logic themselves such as JavaScript or a virus. These actions could occur in the background while the user is only seeing the reader opening a seemingly harmless web page. In Russia, a malicious QR code caused phones that scanned it to send premium texts at a fee of $6 each. QR codes have also been linked to scams in which stickers are placed on parking meters and other devices, posing as quick payment options, as seen in Austin, San Antonio and Boston, among other cities across the United States and Australia.