FA-72641 / Check-digit algorithms / Open access
Code 128 set A scores control characters by code point · case 01
Barcodes carrying tab or other control characters in set A get wrong check symbols.
ROOT CAUSE
Control characters use ord(ch) directly, but in set A they occupy values 64..95.
THE FAILURE
Control characters use ord(ch) directly, but in set A they occupy values 64..95.
Unsuccessful approach: Adding 96 overshoots into the function-code values.
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) 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 ["A", "0%!J\\u0011"]', ['A', '0%!J\x11'], 87], ['regression ["A", "\\u0005\\u00000_;V"]', ['A', '\x05\x000_;V'], 29], ['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 ["A", ",B\\u001e\\u000e_#Y"]', ['A', ',B\x1e\x0e_#Y'], 67], ['regression ["A", "\\u0010\\u0015>D\\u0001\\u0013"]', ['A', '\x10\x15>D\x01\x13'], 71], ['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 ["C", "9158"]', ['C', '9158'], 3]], [['regression ["A", "AB\\t1"]', ['A', 'AB\t1'], 79], ['regression ["A", "\\u0000"]', ['A', '\x00'], 64], ['control ["C", "9158"]', ['C', '9158'], 3], ['control ["C", "32273629"]', ['C', '32273629'], 3], ['control ["C", "976797"]', ['C', '976797'], 9], ['control ["C", "209091"]', ['C', '209091'], 63], ['control ["C", "5357244392"]', ['C', '5357244392'], 49], ['control ["C", "68"]', ['C', '68'], 70]], [['regression ["A", "\\u0005\\u00000_;V"]', ['A', '\x05\x000_;V'], 29], ['regression ["A", "\\u0005\\u0017F"]', ['A', '\x05\x17F'], 48], ['control ["C", "68"]', ['C', '68'], 70], ['control ["B", "PJJ123C"]', ['B', 'PJJ123C'], 55], ['control ["B", "Wikipedia"]', ['B', 'Wikipedia'], 88], ['control ["C", "123456"]', ['C', '123456'], 44], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["B", "a\x7f"]', ['B', 'a\x7f'], 50]], [['regression ["A", "\\u0010\\u0015>D\\u0001\\u0013"]', ['A', '\x10\x15>D\x01\x13'], 71], ['regression ["A", "H\\u0010\\u001c7F"]', ['A', 'H\x10\x1c7F'], 37], ['control ["B", "a\x7f"]', ['B', 'a\x7f'], 50], ['control ["B", "\x7f"]', ['B', '\x7f'], 96], ['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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression ["A", "0%!J\u0011"] | 76 | 87 | Failed |
| regression ["A", "\u0005\u00000_;V"] | 43 | 29 | Failed |
| control ["B", "@w~'"] | 2 | 2 | Passed |
| control ["B", "Ht?"] | 96 | 96 | Passed |
| control ["B", "U?tS;F"] | 8 | 8 | Passed |
| control ["B", ")r"] | 71 | 71 | Passed |
| control ["B", "YyUx>VrW{?"] | 68 | 68 | Passed |
| control ["B", "4Y&P%jOM+J/"] | 24 | 24 | Passed |
SHA-256 / c9c529d9e1310e414c67f149387e0e3b1babf2f600deddcb2092ac7a7dc0db77
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) + 96 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 ["A", "0%!J\\u0011"]', ['A', '0%!J\x11'], 87], ['regression ["A", "\\u0005\\u00000_;V"]', ['A', '\x05\x000_;V'], 29], ['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 ["A", ",B\\u001e\\u000e_#Y"]', ['A', ',B\x1e\x0e_#Y'], 67], ['regression ["A", "\\u0010\\u0015>D\\u0001\\u0013"]', ['A', '\x10\x15>D\x01\x13'], 71], ['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 ["C", "9158"]', ['C', '9158'], 3]], [['regression ["A", "AB\\t1"]', ['A', 'AB\t1'], 79], ['regression ["A", "\\u0000"]', ['A', '\x00'], 64], ['control ["C", "9158"]', ['C', '9158'], 3], ['control ["C", "32273629"]', ['C', '32273629'], 3], ['control ["C", "976797"]', ['C', '976797'], 9], ['control ["C", "209091"]', ['C', '209091'], 63], ['control ["C", "5357244392"]', ['C', '5357244392'], 49], ['control ["C", "68"]', ['C', '68'], 70]], [['regression ["A", "\\u0005\\u00000_;V"]', ['A', '\x05\x000_;V'], 29], ['regression ["A", "\\u0005\\u0017F"]', ['A', '\x05\x17F'], 48], ['control ["C", "68"]', ['C', '68'], 70], ['control ["B", "PJJ123C"]', ['B', 'PJJ123C'], 55], ['control ["B", "Wikipedia"]', ['B', 'Wikipedia'], 88], ['control ["C", "123456"]', ['C', '123456'], 44], ['control ["C", "12345"]', ['C', '12345'], None], ['control ["B", "a\x7f"]', ['B', 'a\x7f'], 50]], [['regression ["A", "\\u0010\\u0015>D\\u0001\\u0013"]', ['A', '\x10\x15>D\x01\x13'], 71], ['regression ["A", "H\\u0010\\u001c7F"]', ['A', 'H\x10\x1c7F'], 37], ['control ["B", "a\x7f"]', ['B', 'a\x7f'], 50], ['control ["B", "\x7f"]', ['B', '\x7f'], 96], ['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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression ["A", "0%!J\u0011"] | 41 | 87 | Failed |
| regression ["A", "\u0005\u00000_;V"] | 22 | 29 | Failed |
| control ["B", "@w~'"] | 2 | 2 | Passed |
| control ["B", "Ht?"] | 96 | 96 | Passed |
| control ["B", "U?tS;F"] | 8 | 8 | Passed |
| control ["B", ")r"] | 71 | 71 | Passed |
| control ["B", "YyUx>VrW{?"] | 68 | 68 | Passed |
| control ["B", "4Y&P%jOM+J/"] | 24 | 24 | Passed |
SHA-256 / 7a238fae76cee09e7de28bed92fbc07da0451e81b2157c0ff8875769314cf6f9
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.277245+00:00.
Case digest / 5191feecefe52d40f8e8a9bafdb02ef69709d59e4ca6d57ab02ba0edb93dbb2e