FAILURE MAP
← Case archive

FA-72636 / Check-digit algorithms / Open access

Code 128 set C encodes single digits · case 01

Numeric barcodes in set C get the wrong check symbol.

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

ROOT CAUSE

Set C values are built from individual digits instead of digit pairs.

VERIFIED REPAIR

Take digits two at a time; each pair is one symbol value 00..99.

Unsuccessful approach: Sliding a two-digit window by one digit produces overlapping pairs.

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(ch) for ch in data]
    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, 1):
        total += pos * v
    return total % 103
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["C", "9158"]', ['C', '9158'], 3], ['regression ["C", "32273629"]', ['C', '32273629'], 3], ['control ["B", "@w~\'"]', ['B', "@w~'"], 2], ['control ["B", "Ht?"]', ['B', 'Ht?'], 96], ['control ["B", "U?tS;F"]', ['B', 'U?tS;F'], 8], ['control ["B", ")r"]', ['B', ')r'], 71], ['control ["B", "YyUx>VrW{?"]', ['B', 'YyUx>VrW{?'], 68], ['control ["B", "4Y&P%jOM+J/"]', ['B', '4Y&P%jOM+J/'], 24]], [['regression ["C", "209091"]', ['C', '209091'], 63], ['regression ["C", "5357244392"]', ['C', '5357244392'], 49], ['control ["B", "4Y&P%jOM+J/"]', ['B', '4Y&P%jOM+J/'], 24], ['control ["B", "wm$|^uemYo/"]', ['B', 'wm$|^uemYo/'], 95], ['control ["B", "UI}*7pnZebjZ"]', ['B', 'UI}*7pnZebjZ'], 10], ['control ["B", "GOJ%^JsFlN="]', ['B', 'GOJ%^JsFlN='], 100], ['control ["B", "{j]OWCR"]', ['B', '{j]OWCR'], 4], ['control ["A", "0%!J\\u0011"]', ['A', '0%!J\x11'], 87]], [['regression ["C", "123456"]', ['C', '123456'], 44], ['regression ["C", "9158"]', ['C', '9158'], 3], ['partial-repair ["C", "32273629"]', ['C', '32273629'], 3], ['control ["A", "0%!J\\u0011"]', ['A', '0%!J\x11'], 87], ['control ["A", "\\u0005\\u00000_;V"]', ['A', '\x05\x000_;V'], 29], ['control ["A", "\\u0005\\u0017F"]', ['A', '\x05\x17F'], 48], ['control ["A", ",B\\u001e\\u000e_#Y"]', ['A', ',B\x1e\x0e_#Y'], 67], ['control ["A", "\\u0010\\u0015>D\\u0001\\u0013"]', ['A', '\x10\x15>D\x01\x13'], 71]], [['regression ["C", "976797"]', ['C', '976797'], 9], ['regression ["C", "209091"]', ['C', '209091'], 63], ['partial-repair ["C", "5357244392"]', ['C', '5357244392'], 49], ['control ["A", "H\\u0010\\u001c7F"]', ['A', 'H\x10\x1c7F'], 37], ['control ["B", "PJJ123C"]', ['B', 'PJJ123C'], 55], ['control ["B", "Wikipedia"]', ['B', 'Wikipedia'], 88], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["A", "AB\\t1"]', ['A', 'AB\t1'], 79]], [['regression ["C", "68"]', ['C', '68'], 70], ['regression ["C", "123456"]', ['C', '123456'], 44], ['partial-repair ["C", "9158"]', ['C', '9158'], 3], ['partial-repair ["C", "32273629"]', ['C', '32273629'], 3], ['control ["A", "\\u0000"]', ['A', '\x00'], 64], ['control ["B", "a\x7f"]', ['B', 'a\x7f'], 50], ['control ["B", "\x7f"]', ['B', '\x7f'], 96], ['control ["B", ""]', ['B', ''], 1]]]
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 ["C", "9158"]603Failed
regression ["C", "32273629"]773Failed
control ["B", "@w~'"]22Passed
control ["B", "Ht?"]9696Passed
control ["B", "U?tS;F"]88Passed
control ["B", ")r"]7171Passed
control ["B", "YyUx>VrW{?"]6868Passed
control ["B", "4Y&P%jOM+J/"]2424Passed

SHA-256 / fc81901d9c11a9b9280d19001e1a0ac477f60da5bd94bcef22646107e5af4b93

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(len(data) - 1)]
    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, 1):
        total += pos * v
    return total % 103
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["C", "9158"]', ['C', '9158'], 3], ['regression ["C", "32273629"]', ['C', '32273629'], 3], ['control ["B", "@w~\'"]', ['B', "@w~'"], 2], ['control ["B", "Ht?"]', ['B', 'Ht?'], 96], ['control ["B", "U?tS;F"]', ['B', 'U?tS;F'], 8], ['control ["B", ")r"]', ['B', ')r'], 71], ['control ["B", "YyUx>VrW{?"]', ['B', 'YyUx>VrW{?'], 68], ['control ["B", "4Y&P%jOM+J/"]', ['B', '4Y&P%jOM+J/'], 24]], [['regression ["C", "209091"]', ['C', '209091'], 63], ['regression ["C", "5357244392"]', ['C', '5357244392'], 49], ['control ["B", "4Y&P%jOM+J/"]', ['B', '4Y&P%jOM+J/'], 24], ['control ["B", "wm$|^uemYo/"]', ['B', 'wm$|^uemYo/'], 95], ['control ["B", "UI}*7pnZebjZ"]', ['B', 'UI}*7pnZebjZ'], 10], ['control ["B", "GOJ%^JsFlN="]', ['B', 'GOJ%^JsFlN='], 100], ['control ["B", "{j]OWCR"]', ['B', '{j]OWCR'], 4], ['control ["A", "0%!J\\u0011"]', ['A', '0%!J\x11'], 87]], [['regression ["C", "123456"]', ['C', '123456'], 44], ['regression ["C", "9158"]', ['C', '9158'], 3], ['partial-repair ["C", "32273629"]', ['C', '32273629'], 3], ['control ["A", "0%!J\\u0011"]', ['A', '0%!J\x11'], 87], ['control ["A", "\\u0005\\u00000_;V"]', ['A', '\x05\x000_;V'], 29], ['control ["A", "\\u0005\\u0017F"]', ['A', '\x05\x17F'], 48], ['control ["A", ",B\\u001e\\u000e_#Y"]', ['A', ',B\x1e\x0e_#Y'], 67], ['control ["A", "\\u0010\\u0015>D\\u0001\\u0013"]', ['A', '\x10\x15>D\x01\x13'], 71]], [['regression ["C", "976797"]', ['C', '976797'], 9], ['regression ["C", "209091"]', ['C', '209091'], 63], ['partial-repair ["C", "5357244392"]', ['C', '5357244392'], 49], ['control ["A", "H\\u0010\\u001c7F"]', ['A', 'H\x10\x1c7F'], 37], ['control ["B", "PJJ123C"]', ['B', 'PJJ123C'], 55], ['control ["B", "Wikipedia"]', ['B', 'Wikipedia'], 88], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["A", "AB\\t1"]', ['A', 'AB\t1'], 79]], [['regression ["C", "68"]', ['C', '68'], 70], ['regression ["C", "123456"]', ['C', '123456'], 44], ['partial-repair ["C", "9158"]', ['C', '9158'], 3], ['partial-repair ["C", "32273629"]', ['C', '32273629'], 3], ['control ["A", "\\u0000"]', ['A', '\x00'], 64], ['control ["B", "a\x7f"]', ['B', 'a\x7f'], 50], ['control ["B", "\x7f"]', ['B', '\x7f'], 96], ['control ["B", ""]', ['B', ''], 1]]]
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 ["C", "9158"]913Failed
regression ["C", "32273629"]733Failed
control ["B", "@w~'"]22Passed
control ["B", "Ht?"]9696Passed
control ["B", "U?tS;F"]88Passed
control ["B", ")r"]7171Passed
control ["B", "YyUx>VrW{?"]6868Passed
control ["B", "4Y&P%jOM+J/"]2424Passed

SHA-256 / 4c128d20e5a2b877550d13ca4e3c7fb928b160fc09e1c953ed66aee5d34d16e6

3 / The verified repair

Exit 0
"""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, 1):
        total += pos * v
    return total % 103
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["C", "9158"]', ['C', '9158'], 3], ['regression ["C", "32273629"]', ['C', '32273629'], 3], ['control ["B", "@w~\'"]', ['B', "@w~'"], 2], ['control ["B", "Ht?"]', ['B', 'Ht?'], 96], ['control ["B", "U?tS;F"]', ['B', 'U?tS;F'], 8], ['control ["B", ")r"]', ['B', ')r'], 71], ['control ["B", "YyUx>VrW{?"]', ['B', 'YyUx>VrW{?'], 68], ['control ["B", "4Y&P%jOM+J/"]', ['B', '4Y&P%jOM+J/'], 24]], [['regression ["C", "209091"]', ['C', '209091'], 63], ['regression ["C", "5357244392"]', ['C', '5357244392'], 49], ['control ["B", "4Y&P%jOM+J/"]', ['B', '4Y&P%jOM+J/'], 24], ['control ["B", "wm$|^uemYo/"]', ['B', 'wm$|^uemYo/'], 95], ['control ["B", "UI}*7pnZebjZ"]', ['B', 'UI}*7pnZebjZ'], 10], ['control ["B", "GOJ%^JsFlN="]', ['B', 'GOJ%^JsFlN='], 100], ['control ["B", "{j]OWCR"]', ['B', '{j]OWCR'], 4], ['control ["A", "0%!J\\u0011"]', ['A', '0%!J\x11'], 87]], [['regression ["C", "123456"]', ['C', '123456'], 44], ['regression ["C", "9158"]', ['C', '9158'], 3], ['partial-repair ["C", "32273629"]', ['C', '32273629'], 3], ['control ["A", "0%!J\\u0011"]', ['A', '0%!J\x11'], 87], ['control ["A", "\\u0005\\u00000_;V"]', ['A', '\x05\x000_;V'], 29], ['control ["A", "\\u0005\\u0017F"]', ['A', '\x05\x17F'], 48], ['control ["A", ",B\\u001e\\u000e_#Y"]', ['A', ',B\x1e\x0e_#Y'], 67], ['control ["A", "\\u0010\\u0015>D\\u0001\\u0013"]', ['A', '\x10\x15>D\x01\x13'], 71]], [['regression ["C", "976797"]', ['C', '976797'], 9], ['regression ["C", "209091"]', ['C', '209091'], 63], ['partial-repair ["C", "5357244392"]', ['C', '5357244392'], 49], ['control ["A", "H\\u0010\\u001c7F"]', ['A', 'H\x10\x1c7F'], 37], ['control ["B", "PJJ123C"]', ['B', 'PJJ123C'], 55], ['control ["B", "Wikipedia"]', ['B', 'Wikipedia'], 88], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["A", "AB\\t1"]', ['A', 'AB\t1'], 79]], [['regression ["C", "68"]', ['C', '68'], 70], ['regression ["C", "123456"]', ['C', '123456'], 44], ['partial-repair ["C", "9158"]', ['C', '9158'], 3], ['partial-repair ["C", "32273629"]', ['C', '32273629'], 3], ['control ["A", "\\u0000"]', ['A', '\x00'], 64], ['control ["B", "a\x7f"]', ['B', 'a\x7f'], 50], ['control ["B", "\x7f"]', ['B', '\x7f'], 96], ['control ["B", ""]', ['B', ''], 1]]]
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 ["C", "9158"]33Passed
regression ["C", "32273629"]33Passed
control ["B", "@w~'"]22Passed
control ["B", "Ht?"]9696Passed
control ["B", "U?tS;F"]88Passed
control ["B", ")r"]7171Passed
control ["B", "YyUx>VrW{?"]6868Passed
control ["B", "4Y&P%jOM+J/"]2424Passed

SHA-256 / fd4640651b54cd4820419950dd4fe6dea3ecdbc2381534868a57692fe3fcaf3d

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.277034+00:00.

Case digest / 534d7cb74483c32038d9a7b057e17b94dcd1a595fc485eee31f70d0169d45765