QR code generator console application

QR Code Generator

Source code: https://github.com/sanje2v/QRCodeGenerator

QR code generators are nothing new – they are all over the internet. Yet, I decided to write one as a console application which I didn’t find any (not that it would be groundbreaking in anyway but just to learn how QR code is implemented). This application implements QR code version 1 and encodes only in alphanumeric mode (hence limited to encoding in uppercase English characters).

This project was not intended to cover all implementations of QR code versions and is not likely to be developed further in the future – but perhaps, a decoder if I feel like it. Rather, I wanted to understand how QR code is generated. One of the most important (and interesting) component is error correction which  covers some interesting topics like number theory, Galois field and polynomial arithmetic. I had a lot of fun implementing these. An unexpected field I got to explore was masking where the specification tries to remove unwanted patterns – i.e. patterns which may cause confusion to decoders. The source code for this project will be helpful to anyone starting to learn QR code encoding.

Aside from the official QR code specification document, http://www.thonky.com/qr-code-tutorial/ provides a good overview with walk-through samples for various steps of the encoding process. Not being a math buff, the guide was especially helpful to me on understanding binary polynomial division in Galois field.

In order for the console application to display the square QR code correctly, the program changes console’s font size and type in function ‘SetConsoleAttributes()’. The font index number used in this function is undocumented and was determined by changing Windows 10 console properties and watching the index number change in Windows API. If you are using non-Windows operating system, please change this function to correct your console font to any monospaced font. Also, the function forces the console to black background with bright white foreground as required by the specification.