The Imitable QR Code

What is a QR Code?

  1. Think of those square black and white chunks of nonsense like a more complex bar code that you see on grocery store items. It contains information that can be decoded by a scanner, and even when damaged, it will still (likely) work.
  2. There are a variety of different formats for encoding
    • Kanji (Japanese / Chinese script)
    • Numeric (0-9)
    • Alphanumeric (0-9, A-Z)
    • Byte (8 bits of whatever!)
    • There are a few more, but they are not widely supported, so I’ll just ignore them!
  3. What allows a QR Code to remain readable even after being damaged is because of error correction, more specifically the reed solomon error correction algorithm.
  4. Fixed patterns, such as the finder pattern allow for cameras to easily lock on to the code, help the decoder determine what version/format its using, etc. Mostly all metadata that is sometimes relevant to encoding, sometimes important for just taking the picture.

Why This Project Hill To Die On?

I’ve always wanted to do something with the rust programming language, but I couldn’t think of anything substantial until I started reading about how QR codes work. There’s nothing in particular that I absolutely needed to have in Rust that other languages couldn’t do - and after the fact, there wasn’t really anything fancy that I did in Rust to make this thing work. But what it did do was push me into thinking critically about the language, how I code, and in data structures. I made plenty of mistakes while working on this, some very expensive ones, but I am fortunate enough to have realized them.

image/svg+xml D1 D14 D2 D3 D4 D5 D6 D7 D8 D9 D10 D11 D12 D13 D15 D16 D17 D18 D19 D21 D22 D23 D24 D25 D26 E1 E2 E24 E3 E4 E5 E6 E7 E8 E9 E10 E11 E33 E12 E13 E14 E15 E16 E17 E18 E19 E20 E21 E22 E23 E25 E26 E27 E28 E29 E30 E31 E32 E34 E35 E36 E37 E38 E39 E40 E41 E42 E43 E44 X D: Data, E: Error Correction, X: Unused Fixed Patterns Format Info D20 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 6 5 4 3 2 1 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 Error Correction Level H is shown Bit order (7 is the most significant bit): Block 1 Codewords: D1–D13, E1–E22 Block 2 Codewords: D14–D26, E23–E44 Message Data: D1–D13, D14–D26 7 0 EXEEEXHJS EXD

There were many resources I used throughout the duration of the this project. This one in particular was crazy useful - but certainly not perfect. Because of how awesome WebAssembly is, I was able to figure out how to port my Rust program onto here - so similar to above, I used a canvas to map out how data gets encoded. I’ll go more in depth later, but this was just too much fun to not share now!