Chapter 04 of 22 Part I: Digital Foundations

The Incredible QR Code

Each project below is tailored to a specific algorithm and scientific question from Chapter 04, with concrete inputs, verifiable numerical outputs, boundary cases, and links to the related lab and pioneer.

Project 1 of 3 · v1-c04-p01 Intermediate · ~35 min

Version-1 QR Matrix Builder

Lab activity: 1 / Create a real QR symbol · Related code: block-01.js, block-04.js · Pioneer: View profile

Real-World Problem: 1D barcodes hold only ~13 digits; mobile links and tickets require compact 2D symbols readable by phone cameras.
Scientific Question: How do finder patterns, timing strips, format bits, and masked data modules share a 21×21 grid?

Objective: Encode short text into a real Version-1 QR code, inspect functional vs. data regions, and test mask selection.

Hypothesis to Test: Applying the lowest-penalty XOR mask eliminates large uniform dark/light patches without altering decoded text.

Step-by-Step Implementation

  1. Place the three 7×7 finder patterns (top-left, top-right, bottom-left) plus separators and timing patterns.
  2. Encode the text in byte mode with 4-bit mode indicator, 8-bit length, payload, terminator, and pad bytes.
  3. Generate Reed-Solomon error-correction codewords over GF(256) and interleave into the matrix.
  4. Apply mask patterns and inspect format-info modules that tell scanners which mask and EC level were used.
Concrete Input: Text: "HELLO" at Error Correction Level M (Version 1, 21×21).
Expected Output: 16 data codewords + 10 Reed-Solomon parity codewords placed in zigzag columns around finder patterns.

Test Cases: "HELLO" Level M -> 26 total codewords (16 data, 10 parity); Quiet zone = 4 modules.

Boundary Condition: Version 1-M byte mode holds at most 14 bytes; longer strings require Version 2 (25×25) or higher.

Common Mistake to Avoid: Masking the finder patterns or format bits (masks apply ONLY to data/EC modules).

Interpreting Results: QR symbols separate structural framing (finder/format) from error-protected payload codewords.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 04 before testing the boundary case: Version 1-M byte mode holds at most 14 bytes; longer strings require Version 2 (25×25) or higher.

Extension Challenge: Compare module density between Level L (~7% codeword recovery) and Level H (~30% codeword recovery) for the same URL.

Reflection Question: Why did Masahiro Hara's Denso Wave team choose a 1:1:3:1:1 black-white ratio for QR finder squares?

Project 2 of 3 · v1-c04-p02 Applied · ~30 min

Reed-Solomon Codeword Damage Experiment

Lab activity: Data and correction codewords · Related code: block-02.js, block-05.js · Pioneer: View profile

Real-World Problem: Printed QR stickers on packages and signs get scratched, wet, or partially covered.
Scientific Question: Why does damaging a finder pattern or format strip break decoding far faster than damaging data codewords?

Objective: Compare codeword-level error recovery at Levels L, M, Q, and H against structural damage to finder/format regions.

Hypothesis to Test: Level H recovers roughly 30% of corrupted codewords, but destroying finder patterns breaks scanning even if fewer than 10% of modules are damaged.

Step-by-Step Implementation

  1. Generate a QR symbol at Level L and erase individual data modules until decoding fails.
  2. Repeat at Level H and record the higher codeword tolerance.
  3. Reset and erase modules inside a finder square or format-info strip.
  4. Document why EC level percentages describe codeword proportions, not arbitrary physical area.
Concrete Input: Version 1-H QR code: corrupt 4 data codewords vs. erase top-left finder square.
Expected Output: 4 corrupted data codewords -> recovered cleanly; erased finder pattern -> scanner fails to locate grid.

Test Cases: V1-M (10 parity bytes) corrects up to 5 unknown-location byte errors (2t <= n - k).

Boundary Condition: One damaged module inside 8 different bytes counts as 8 corrupted codewords, whereas 8 damaged modules inside 1 byte count as only 1 codeword.

Common Mistake to Avoid: Claiming Level H guarantees recovery from any 30% physical tear across the symbol.

Interpreting Results: Reed-Solomon operates on 8-bit codewords, making burst errors inside single bytes far easier to repair than scattered bit errors.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 04 before testing the boundary case: One damaged module inside 8 different bytes counts as 8 corrupted codewords, whereas 8 damaged modules inside 1 byte count as only 1 codeword.

Extension Challenge: Calculate how many corrupted bytes V1-L (7 EC bytes) vs. V1-H (17 EC bytes) can correct: floor(7/2)=3 vs. floor(17/2)=8.

Reflection Question: Why do QR stickers with logos in the center rely on Level H and avoid touching the three corners?

Project 3 of 3 · v1-c04-p03 Intermediate · ~25 min

Duplicate-Label & QR URL Safety Auditor

Lab activity: 2 / Damage and repair · Related code: block-03.js, block-04.js, block-05.js · Pioneer: View profile

Real-World Problem: Attackers sometimes paste malicious QR stickers over legitimate public signs ("quishing").
Scientific Question: How can software inspect decoded QR payloads safely before opening a link?

Objective: Build a payload classifier that flags duplicate inventory tags, non-HTTPS links, and lookalike domains.

Hypothesis to Test: Parsing a QR payload as plain text and inspecting its hostname before navigation prevents silent phishing redirects.

Step-by-Step Implementation

  1. Ingest a list of decoded QR strings from Activity 3 and check uniqueness with a Set.
  2. Parse URL payloads using the standard URL() constructor inside try/catch.
  3. Display protocol (https vs. http), exact hostname, and path clearly to the user.
  4. Require explicit user confirmation before navigating to external domains.
Concrete Input: Batch of 6 decoded payloads including a duplicate asset ID and a lookalike domain.
Expected Output: Flags 1 duplicate label and warns on untrusted/non-HTTPS URL before opening.

Test Cases: Duplicate ID -> flagged; "javascript:alert(1)" -> rejected as unsafe protocol.

Boundary Condition: Non-URL text (plain strings, Wi-Fi config) must not crash the URL parser.

Common Mistake to Avoid: Checking URLs with naive string.includes("example.com") which is fooled by example.com.evil.test.

Interpreting Results: A QR code is only a machine-readable carrier; safety depends on validating the decoded destination.

Show Hint, Extension Challenge & Reflection

Hint: Review the worked example and equation in Chapter 04 before testing the boundary case: Non-URL text (plain strings, Wi-Fi config) must not crash the URL parser.

Extension Challenge: Add punycode (xn--) detection to warn users about homograph lookalike domains.

Reflection Question: How should public transit or museum apps display scanned QR destinations to teenagers?