FAILURE MAP
← Case archive

FA-72631 / Check-digit algorithms / Open access

Code 128 weights the first data symbol by zero · case 01

Every barcode gets the wrong check symbol.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Positions are enumerated from 0, so the first data symbol drops out and every later weight is one low.

THE FAILURE

Positions are enumerated from 0, so the first data symbol drops out and every later weight is one low.

Unsuccessful approach: Starting positions at 2 treats the start code as if it occupied position 1 twice.

Case contract

Code 128 symbol check value. Start codes A/B/C have values 103/104/105 (other codes: None). Code B accepts characters 32..127 (value ord - 32); code A accepts 0..95 (values ord - 32, controls ord + 64); code C accepts an even number of ASCII digits taken in pairs (value 0..99). The checksum is (start + sum(position * value)) mod 103 with positions starting at 1 after the start code. Invalid data returns None.

Why this case matters

Label printers compute the Code 128 check symbol before rendering shipping barcodes.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, data):
    starts = {'A': 103, 'B': 104, 'C': 105}
    if code not in starts:
        return None
    if code == 'C':
        if len(data) % 2 or not data.isascii() or not data.isdigit():
            return None
        values = [int(data[i:i + 2]) for i in range(0, len(data), 2)]
    elif code == 'B':
        if any(not 32 <= ord(ch) <= 127 for ch in data):
            return None
        values = [ord(ch) - 32 for ch in data]
    else:
        if any(not 0 <= ord(ch) <= 95 for ch in data):
            return None
        values = [ord(ch) - 32 if ord(ch) >= 32 else ord(ch) + 64 for ch in data]
    total = starts[code]
    for pos, v in enumerate(values):
        total += pos * v
    return total % 103
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["B", "@w~\'"]', ['B', "@w~'"], 2], ['regression ["B", "Ht?"]', ['B', 'Ht?'], 96], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["B", ""]', ['B', ''], 1], ['control ["D", "X"]', ['D', 'X'], None], ['control ["A", "abc"]', ['A', 'abc'], None], ['control ["C", "00"]', ['C', '00'], 2], ['control ["B", " "]', ['B', ' '], 1]], [['regression ["B", ")r"]', ['B', ')r'], 71], ['regression ["B", "YyUx>VrW{?"]', ['B', 'YyUx>VrW{?'], 68], ['control ["B", " "]', ['B', ' '], 1], ['control ["B", "café"]', ['B', 'café'], None], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["B", ""]', ['B', ''], 1], ['control ["D", "X"]', ['D', 'X'], None], ['control ["A", "abc"]', ['A', 'abc'], None]], [['regression ["B", "wm$|^uemYo/"]', ['B', 'wm$|^uemYo/'], 95], ['regression ["B", "UI}*7pnZebjZ"]', ['B', 'UI}*7pnZebjZ'], 10], ['control ["A", "abc"]', ['A', 'abc'], None], ['control ["C", "00"]', ['C', '00'], 2], ['control ["B", " "]', ['B', ' '], 1], ['control ["B", "café"]', ['B', 'café'], None], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["B", ""]', ['B', ''], 1]], [['regression ["B", "{j]OWCR"]', ['B', '{j]OWCR'], 4], ['regression ["C", "9158"]', ['C', '9158'], 3], ['control ["B", ""]', ['B', ''], 1], ['control ["D", "X"]', ['D', 'X'], None], ['control ["A", "abc"]', ['A', 'abc'], None], ['control ["C", "00"]', ['C', '00'], 2], ['control ["B", " "]', ['B', ' '], 1], ['control ["B", "café"]', ['B', 'café'], None]], [['regression ["C", "976797"]', ['C', '976797'], 9], ['regression ["C", "209091"]', ['C', '209091'], 63], ['control ["B", "café"]', ['B', 'café'], None], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["B", ""]', ['B', ''], 1], ['control ["D", "X"]', ['D', 'X'], None], ['control ["A", "abc"]', ['A', 'abc'], None], ['control ["C", "00"]', ['C', '00'], 2]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression ["B", "@w~'"]912Failed
regression ["B", "Ht?"]4496Failed
control ["C", "12345"]NoneNonePassed
control ["B", ""]11Passed
control ["D", "X"]NoneNonePassed
control ["A", "abc"]NoneNonePassed
control ["C", "00"]22Passed
control ["B", " "]11Passed

SHA-256 / 967319c9cd8d07b500e4d7ecaf4d5395454e189c263f6c073775159f6e1008f7

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(code, data):
    starts = {'A': 103, 'B': 104, 'C': 105}
    if code not in starts:
        return None
    if code == 'C':
        if len(data) % 2 or not data.isascii() or not data.isdigit():
            return None
        values = [int(data[i:i + 2]) for i in range(0, len(data), 2)]
    elif code == 'B':
        if any(not 32 <= ord(ch) <= 127 for ch in data):
            return None
        values = [ord(ch) - 32 for ch in data]
    else:
        if any(not 0 <= ord(ch) <= 95 for ch in data):
            return None
        values = [ord(ch) - 32 if ord(ch) >= 32 else ord(ch) + 64 for ch in data]
    total = starts[code]
    for pos, v in enumerate(values, 2):
        total += pos * v
    return total % 103
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["B", "@w~\'"]', ['B', "@w~'"], 2], ['regression ["B", "Ht?"]', ['B', 'Ht?'], 96], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["B", ""]', ['B', ''], 1], ['control ["D", "X"]', ['D', 'X'], None], ['control ["A", "abc"]', ['A', 'abc'], None], ['control ["C", "00"]', ['C', '00'], 2], ['control ["B", " "]', ['B', ' '], 1]], [['regression ["B", ")r"]', ['B', ')r'], 71], ['regression ["B", "YyUx>VrW{?"]', ['B', 'YyUx>VrW{?'], 68], ['control ["B", " "]', ['B', ' '], 1], ['control ["B", "café"]', ['B', 'café'], None], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["B", ""]', ['B', ''], 1], ['control ["D", "X"]', ['D', 'X'], None], ['control ["A", "abc"]', ['A', 'abc'], None]], [['regression ["B", "wm$|^uemYo/"]', ['B', 'wm$|^uemYo/'], 95], ['regression ["B", "UI}*7pnZebjZ"]', ['B', 'UI}*7pnZebjZ'], 10], ['control ["A", "abc"]', ['A', 'abc'], None], ['control ["C", "00"]', ['C', '00'], 2], ['control ["B", " "]', ['B', ' '], 1], ['control ["B", "café"]', ['B', 'café'], None], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["B", ""]', ['B', ''], 1]], [['regression ["B", "{j]OWCR"]', ['B', '{j]OWCR'], 4], ['regression ["C", "9158"]', ['C', '9158'], 3], ['control ["B", ""]', ['B', ''], 1], ['control ["D", "X"]', ['D', 'X'], None], ['control ["A", "abc"]', ['A', 'abc'], None], ['control ["C", "00"]', ['C', '00'], 2], ['control ["B", " "]', ['B', ' '], 1], ['control ["B", "café"]', ['B', 'café'], None]], [['regression ["C", "976797"]', ['C', '976797'], 9], ['regression ["C", "209091"]', ['C', '209091'], 63], ['control ["B", "café"]', ['B', 'café'], None], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["B", ""]', ['B', ''], 1], ['control ["D", "X"]', ['D', 'X'], None], ['control ["A", "abc"]', ['A', 'abc'], None], ['control ["C", "00"]', ['C', '00'], 2]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
regression ["B", "@w~'"]162Failed
regression ["B", "Ht?"]4596Failed
control ["C", "12345"]NoneNonePassed
control ["B", ""]11Passed
control ["D", "X"]NoneNonePassed
control ["A", "abc"]NoneNonePassed
control ["C", "00"]22Passed
control ["B", " "]11Passed

SHA-256 / 8a9dfdf27d2d20d50567fb2e16b0a1cfea1112ddcc64f0e35b0969d01033783b

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

Verification & scope

A deterministic, bounded teaching model of the named scheme under the stated contract; not a certified validator. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:48:40.263652+00:00.

Case digest / 72ed4a3b11d56336d437b34445f94609465e858b3a1ca2ec7acb85ba34cad36c