K-Galalem
K-Galalem

Reputation: 320

How are Error Correction Levels Encrypted in QR Code?

I'm trying to create my own QR Code Generator library and algorithms. I made a little research about the steps of creating a QR Code, but got stuck with this ambiguous point.

Error Correction Level are listed as following:

In QR Codes Black = 1 & White = 0

According to Wikipedia this how levels are coded

According to lots of other Websites & Tutorials this how levels are coded

Which one do I trust or I have missed a critical step or something to identify that

Upvotes: 0

Views: 788

Answers (1)

K-Galalem
K-Galalem

Reputation: 320

The Answer is BOTH, yes both are correct but are a different phases:

  • The one in Wikipedia show how the Error Correction Level is displayed on a READY QR CODE (final preview)

  • The others show how the Error Correction Level should look like Before MASK

In QR Codes not only Data and error correction are masked, also format strings (15 bits) are masked too but with a particular mask:

The 15 bits format string are XOR-ed with the following 15 bits 101010000010010

So as Error Correction Level is always represented in the first 2 bits it will always be masked (XOR-ed) with these 2 bits 10

So the final result would look like the following:

  • L : 1 (01 binary) -> 01^10 = 11 -> Becomes 3 (11 binary)
  • M : 0 (00 binary) -> 00^10 = 10 -> Becomes 2 (10 binary)
  • Q : 3 (11 binary) -> 11^10 = 01 -> Becomes 1 (01 binary)
  • H : 2 (10 binary) -> 10^10 = 00 -> Becomes 0 (00 binary)

Upvotes: 0

Related Questions