How to make a QR code that is complicated and difficult to read super simple



QR codes are widely used for links to websites and e-commerce payments, but many people have experienced such things as 'complex QR codes are printed small and cannot be read!'. Mr. Huon Wilson, who has participated in the development of programming languages 'Swift ' and ' Rust ', explains how to convert such 'complex and difficult-to-read QR code' into 'simple and easy-to-read QR code'.

Mechanical sympathy for QR codes: making NSW check-in better | Huon on the internet
https://huonw.github.io/blog/2021/10/nsw-covid-qr/

In New South Wales, Australia, where Mr. Wilson lives, QR codes for tracking pandemic behavior are posted at restaurants and retail stores. However, if you print the 'File that describes the QR code and how to use the QR code' distributed from New South Wales on A4 copy paper, the size of the QR code will be about 5 cm x 5 cm, and the size of the QR code will be about 5 cm x 5 cm. Combined with the complexity, it will be difficult to read. Dissatisfied with this, Wilson published on his website a way to make it easier to read the QR code.



First, Wilson cites 'printing a large QR code' as a 'ready-to-use solution'. The files distributed from New South Wales spend most of the paper area on 'explaining how to read the QR code and how to use the service app', but it has already been a long time since the QR code measures started. Therefore, there is no problem even if the explanation column is made smaller.



According to Mr. Wilson, the QR code in question contains the long URL, such as 'https://www.service.nsw.gov.au/campaign/service-nsw-mobile-app?data=eyJ0IjoiY292aWQxOV9idXNpbmVzcyIsImJpZCI6IjEyMTMyMSIsImJuYW1lIjoiVGVzdCBOU1cgR292ZXJubWVudCBRUiBjb2RlIiwiYmFkZHJlc3MiOiJCdXNpbmVzcyBhZGRyZXNzIGdvZXMgaGVyZSAifQ==' The shorter this URL is, the simpler the QR code can be. Therefore, Mr. Wilson explains how to simplify while preserving the information contained in the URL in the following five steps.

◆ Step 1: Reduce error correction capability
◆ Step 2: Delete unnecessary information
◆ Step 3: Change the encoding format
◆ Step 4: Omit paths and domains
◆ Step 5: Remove offline support

◆ Step 1: Reduce error correction capability
The QR code has an 'error correction function ' that allows you to display correct data even if a part of the code is dirty or damaged. This error correction function has four levels of ability, 'Level H', 'Level Q', 'Level M', and 'Level L', in descending order of ability. The lower the ability, the simpler the QR code. Wilson said that the QR code in question is 'level Q' because of the balance between error correction capability and the simplicity of the QR code, considering that it is posted in an environment where reading errors are likely to occur, such as inside the glass of a store. You have selected error correction.



◆ Step 2: Delete unnecessary information
URL ',' https://www.service.nsw.gov.au/campaign/service-nsw-mobile-app?data=eyJ0IjoiY292aWQxOV9idXNpbmVzcyIsImJpZCI6IjEyMTMyMSIsImJuYW1lIjoiVGVzdCBOU1cgR292ZXJubWVudCBRUiBjb2RlIiwiYmFkZHJlc3MiOiJCdXNpbmVzcyBhZGRyZXNzIGdvZXMgaGVyZSAifQ== stored in the QR code 'is divided into parts, such as the following ..

Scheme 'https: //'
Domain 'www.service.nsw.gov.au'
Path 'campaign / service-nsw-mobile-app'
Query 'data = eyJ0IjoiY292aW (...) yZSAifQ =='



Of these parts, the query is Base64- encoded data written in JSON format , and when decoded in Base64, the following JSON file appears.

{
't': 'covid19_business',
'bid': '121321',
'bname': 'Test NSW Government QR code',
'baddress': 'Business address goes here'
}



According to Mr. Wilson, the following part of the above JSON file that shows the address of the company posting the QR code is not used in the actual service.

'baddress': 'Business address goes here'



If you delete the unused part and re-encode it with Base64, the URL will be shortened and the QR code will be simplified as follows.



◆ Step 3: Change the encoding format
QR code includes 'number data mode' that can handle only numbers, 'alphabet data mode' that can handle upper alphabets and some symbols in addition to numbers, '8-bit byte data mode' that can handle arbitrary data, and kanji. There are 'Kanji data mode' that can be handled and 'Mixed mode' that can handle them in combination, and each character is in the order of 'Numeric data mode', 'Alphabet data mode', '8-bit byte data mode', and 'Kanji data mode'. Increases the number of bits in. Since it is necessary to keep the number of bits small to simplify the QR code, Wilson adopted a mixed mode of 'alphanumeric data mode' and '8-bit byte data mode', and the URL is in the upper alphabet as much as possible. I decided to describe it in.

Of the URL parts, schemes and domains are not case sensitive and can be written in uppercase. In addition, the path can be written in uppercase because the administrator can freely decide it. Applying this, the URL looks like this:

HTTPS: //WWW.SERVICE.NSW.GOV.AU/CAMPAIGN/SERVICE-NSW-MOBILE-APP?DATA=eyJ0IjoiY292aWQxOV9idXNpbmVzcyIsImJpZCI6IjEyMTMyMSIsImJuYW1lIjoiVGVzdCBOU1cgR2



As mentioned above, the query contains the following JSON files.

{
't': 'covid19_business',
'bid': '121321',
'bname': 'Test NSW Government QR code'
}



Wilson pointed out that the extension of the character string by encoding to Base64 and the symbols such as '{' '}' '' '': '', 'contained in the JSON file is causing the increase in data size, and JSON is I decided to adopt the method of including the information contained in the file directly in the URL.

HTTPS: //WWW.SERVICE.NSW.GOV.AU/CAMPAIGN/SERVICE-NSW-MOBILE-APP/121321/Test+NSW+Government+QR+code



As a result, the QR code has been simplified as follows.



◆ Step 4: Omit paths and domains
The URL path 'SERVICE-NSW-MOBILE-APP' can be set by the administrator to any character string. For example, if the path is a single letter of the alphabet 'C', the QR code will be simplified as follows.



Similarly, the domain 'WWW.SERVICE.NSW.GOV.AU' can be changed to a shorter domain. .. Wilson said that the .gov domain is indispensable to ensure the reliability of the URL, and adopted 'S.NSW.GOV.AU' as the domain. The URL is now as follows.

HTTPS: //S.NSW.GOV.AU/C/121321/Test+NSW+Government+QR+code



Expressing this in a QR code looks like this (better domain). I was able to convert the original complex QR code (original) into a simple QR code while preserving the information.



◆ Step 5: Remove offline support
The completed URL includes the part showing the name of the company posting the QR code ('Test + NSW + Government + QR + code' in this URL). According to Mr. Wilson, this part is responsible for displaying the company name on the screen of smartphones etc. when the user scans the QR code. Since New South Wales only needs to know the company ID ('121321' in this URL) to track and manage citizens, if you remove the function 'Display company name on user's device', the URL will be as follows It can be shortened like.

HTTPS: //S.NSW.GOV.AU/C/121321



This makes the QR code look very simple as shown below.



As mentioned above, the QR code provided by New South Wales will be converted into a QR code that is easy to read while preserving the information. Also, according to Wilson, the QR code in New South Wales is not encrypted, so it is easy to trick the tracking service. From these things, Wilson argues that New South Wales should have used the right technology.

In addition, the social news site Hacker News is discussing how to further simplify the QR code created by Mr. Wilson, but for that purpose it is necessary to reduce the error correction ability.

in Web Service, Posted by log1o_hf