FAILURE MAP
← Case archive

FA-79476 / Barcode symbology encoding / Open access

Full ASCII control escapes are shifted by one letter · case 01

A tab encodes as $J (line feed) and data separators become the wrong control codes.

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

ROOT CAUSE

Control code o is mapped to letter chr(o + 65) instead of chr(o + 64).

VERIFIED REPAIR

Map control code 1 to $A, so the letter is chr(o + 64).

Unsuccessful approach: Using lowercase letters produces characters Code 39 cannot encode.

Case contract

Encode text for Code 39 with a wide:narrow ratio of 2 or 3. Standard mode accepts only the 43 characters 0-9 A-Z - . space $ / + %. Full ASCII mode maps lowercase to "+" plus the capital, controls 1..26 to "$" plus A..Z, NUL to %U, 27..31 to %A..%E, DEL to %T, and punctuation (including the four standard shift characters $ % + /) to its two-character escape. Every symbol character, including the start/stop "*", has 6 narrow and 3 wide elements, and one narrow gap separates adjacent characters. Return the framed data and the total width in narrow modules.

Why this case matters

Retail, logistics, pharmacy and document workflows depend on encoders that produce exactly the module pattern, code-set switches, separators and quiet zones scanners expect; one misplaced module or separator makes a label unreadable or, worse, scan as different data.

1 / The failure

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

N = 1
observations = []
def solve(text, mode, ratio):
    std = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'
    if ratio not in (2, 3):
        return {'error': 'ratio'}
    if mode == 'standard':
        for ch in text:
            if ch not in std:
                return {'error': 'char', 'char': ch}
        enc = text
    else:
        punct = {'$': '/D', '%': '/E', '+': '/K', '/': '/O', '!': '/A', '"': '/B', '#': '/C', '&': '/F', "'": '/G',
                 '(': '/H', ')': '/I', '*': '/J', ',': '/L', ':': '/Z', ';': '%F', '<': '%G', '=': '%H', '>': '%I',
                 '?': '%J', '@': '%V', '[': '%K', '\\': '%L', ']': '%M', '^': '%N', '_': '%O', '`': '%W',
                 '{': '%P', '|': '%Q', '}': '%R', '~': '%S'}
        enc = ''
        for ch in text:
            o = ord(ch)
            if o > 127:
                return {'error': 'char', 'char': ch}
            if ch in punct:
                enc += punct[ch]
            elif 'a' <= ch <= 'z':
                enc += '+' + ch.upper()
            elif 1 <= o <= 26:
                enc += '$' + chr(o + 65)
            elif o == 0:
                enc += '%U'
            elif 27 <= o <= 31:
                enc += '%' + chr(o - 27 + 65)
            elif o == 127:
                enc += '%T'
            else:
                enc += ch
    count = len(enc) + 2
    return {'data': '*' + enc + '*', 'modules': count * (6 + 3 * ratio) + (count - 1)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('AB\t', 'full', 2), {'data': '*AB$I*', 'modules': 77}], [('Z-9x\t', 'full', 2), {'data': '*Z-9+X$I*', 'modules': 116}], [('café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7PN/7', 'full', 1), {'error': 'ratio'}], [('a+ba+b', 'full', 4), {'error': 'ratio'}], [('Z-9a+blot', 'standard', 2), {'error': 'char', 'char': 'a'}], [('café\t', 'full', 4), {'error': 'ratio'}], [('\t$5', 'full', 2), {'data': '*$I/D5*', 'modules': 90}]], [[('\t#1', 'full', 2), {'data': '*$I/C1*', 'modules': 90}], [('\t\x1b', 'full', 2), {'data': '*$I%A*', 'modules': 77}], [('', 'standard', 1), {'error': 'ratio'}], [('\x1blotlot', 'full', 2), {'data': '*%A+L+O+T+L+O+T*', 'modules': 207}], [('#1', 'full', 2), {'data': '*/C1*', 'modules': 64}], [('ABa+b', 'full', 2), {'data': '*AB+A/K+B*', 'modules': 129}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('\t', 'full', 3), {'data': '*$I*', 'modules': 63}]], [[('\t#1*', 'full', 3), {'data': '*$I/C1/J*', 'modules': 143}], [('\x7fq\t', 'full', 3), {'data': '*%T+Q$I*', 'modules': 127}], [('a+bAB', 'full', 2), {'data': '*+A/K+BAB*', 'modules': 129}], [('#1café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7Z-9', 'full', 2), {'data': '*ABPN/O7Z-9*', 'modules': 155}], [(' ', 'full', 1), {'error': 'ratio'}], [('$5 \x00', 'full', 2), {'data': '*/D5 %U*', 'modules': 103}], [('\x00\t50%', 'full', 2), {'data': '*%U$I50/E*', 'modules': 129}]], [[('\t*q', 'full', 3), {'data': '*$I/J+Q*', 'modules': 127}], [('qPN/7café', 'full', 2), {'error': 'char', 'char': 'é'}], [('AB\x00 ', 'full', 1), {'error': 'ratio'}], [('*', 'full', 2), {'data': '*/J*', 'modules': 51}], [('AB12', 'standard', 2), {'data': '*AB12*', 'modules': 77}], [('#1café', 'full', 2), {'error': 'char', 'char': 'é'}], [(' ABPN/7', 'full', 1), {'error': 'ratio'}], [('\t\x7f', 'full', 3), {'data': '*$I%T*', 'modules': 95}]], [[('\t\t', 'full', 3), {'data': '*$I$I*', 'modules': 95}], [('  \t', 'full', 2), {'data': '*  $I*', 'modules': 77}], [('\x00', 'full', 1), {'error': 'ratio'}], [('', 'standard', 2), {'data': '**', 'modules': 25}], [('', 'standard', 1), {'error': 'ratio'}], [('\x7f\x00', 'full', 4), {'error': 'ratio'}], [('$5a+bAB', 'full', 3), {'data': '*/D5+A/K+BAB*', 'modules': 207}], [('50% \t', 'full', 3), {'data': '*50/E $I*', 'modules': 143}]]]
labels = ["regression: control character escape letter", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), 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: control character escape letter 0{'data': '*AB$J*', 'modules': 77}{'data': '*AB$I*', 'modules': 77}Failed
repair trap 1{'data': '*Z-9+X$J*', 'modules': 116}{'data': '*Z-9+X$I*', 'modules': 116}Failed
combined fault 2{'error': 'ratio'}{'error': 'ratio'}Passed
control 3{'error': 'ratio'}{'error': 'ratio'}Passed
control 4{'error': 'ratio'}{'error': 'ratio'}Passed
boundary 5{'char': 'a', 'error': 'char'}{'char': 'a', 'error': 'char'}Passed
boundary 6{'error': 'ratio'}{'error': 'ratio'}Passed
control 7{'data': '*$J/D5*', 'modules': 90}{'data': '*$I/D5*', 'modules': 90}Failed

SHA-256 / 1c5890fe36ae1b119af7bbe9bfd4f2194be0bb1a7e37d01172839863f4a4638f

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(text, mode, ratio):
    std = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'
    if ratio not in (2, 3):
        return {'error': 'ratio'}
    if mode == 'standard':
        for ch in text:
            if ch not in std:
                return {'error': 'char', 'char': ch}
        enc = text
    else:
        punct = {'$': '/D', '%': '/E', '+': '/K', '/': '/O', '!': '/A', '"': '/B', '#': '/C', '&': '/F', "'": '/G',
                 '(': '/H', ')': '/I', '*': '/J', ',': '/L', ':': '/Z', ';': '%F', '<': '%G', '=': '%H', '>': '%I',
                 '?': '%J', '@': '%V', '[': '%K', '\\': '%L', ']': '%M', '^': '%N', '_': '%O', '`': '%W',
                 '{': '%P', '|': '%Q', '}': '%R', '~': '%S'}
        enc = ''
        for ch in text:
            o = ord(ch)
            if o > 127:
                return {'error': 'char', 'char': ch}
            if ch in punct:
                enc += punct[ch]
            elif 'a' <= ch <= 'z':
                enc += '+' + ch.upper()
            elif 1 <= o <= 26:
                enc += '$' + chr(o + 96)
            elif o == 0:
                enc += '%U'
            elif 27 <= o <= 31:
                enc += '%' + chr(o - 27 + 65)
            elif o == 127:
                enc += '%T'
            else:
                enc += ch
    count = len(enc) + 2
    return {'data': '*' + enc + '*', 'modules': count * (6 + 3 * ratio) + (count - 1)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('AB\t', 'full', 2), {'data': '*AB$I*', 'modules': 77}], [('Z-9x\t', 'full', 2), {'data': '*Z-9+X$I*', 'modules': 116}], [('café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7PN/7', 'full', 1), {'error': 'ratio'}], [('a+ba+b', 'full', 4), {'error': 'ratio'}], [('Z-9a+blot', 'standard', 2), {'error': 'char', 'char': 'a'}], [('café\t', 'full', 4), {'error': 'ratio'}], [('\t$5', 'full', 2), {'data': '*$I/D5*', 'modules': 90}]], [[('\t#1', 'full', 2), {'data': '*$I/C1*', 'modules': 90}], [('\t\x1b', 'full', 2), {'data': '*$I%A*', 'modules': 77}], [('', 'standard', 1), {'error': 'ratio'}], [('\x1blotlot', 'full', 2), {'data': '*%A+L+O+T+L+O+T*', 'modules': 207}], [('#1', 'full', 2), {'data': '*/C1*', 'modules': 64}], [('ABa+b', 'full', 2), {'data': '*AB+A/K+B*', 'modules': 129}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('\t', 'full', 3), {'data': '*$I*', 'modules': 63}]], [[('\t#1*', 'full', 3), {'data': '*$I/C1/J*', 'modules': 143}], [('\x7fq\t', 'full', 3), {'data': '*%T+Q$I*', 'modules': 127}], [('a+bAB', 'full', 2), {'data': '*+A/K+BAB*', 'modules': 129}], [('#1café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7Z-9', 'full', 2), {'data': '*ABPN/O7Z-9*', 'modules': 155}], [(' ', 'full', 1), {'error': 'ratio'}], [('$5 \x00', 'full', 2), {'data': '*/D5 %U*', 'modules': 103}], [('\x00\t50%', 'full', 2), {'data': '*%U$I50/E*', 'modules': 129}]], [[('\t*q', 'full', 3), {'data': '*$I/J+Q*', 'modules': 127}], [('qPN/7café', 'full', 2), {'error': 'char', 'char': 'é'}], [('AB\x00 ', 'full', 1), {'error': 'ratio'}], [('*', 'full', 2), {'data': '*/J*', 'modules': 51}], [('AB12', 'standard', 2), {'data': '*AB12*', 'modules': 77}], [('#1café', 'full', 2), {'error': 'char', 'char': 'é'}], [(' ABPN/7', 'full', 1), {'error': 'ratio'}], [('\t\x7f', 'full', 3), {'data': '*$I%T*', 'modules': 95}]], [[('\t\t', 'full', 3), {'data': '*$I$I*', 'modules': 95}], [('  \t', 'full', 2), {'data': '*  $I*', 'modules': 77}], [('\x00', 'full', 1), {'error': 'ratio'}], [('', 'standard', 2), {'data': '**', 'modules': 25}], [('', 'standard', 1), {'error': 'ratio'}], [('\x7f\x00', 'full', 4), {'error': 'ratio'}], [('$5a+bAB', 'full', 3), {'data': '*/D5+A/K+BAB*', 'modules': 207}], [('50% \t', 'full', 3), {'data': '*50/E $I*', 'modules': 143}]]]
labels = ["regression: control character escape letter", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), 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: control character escape letter 0{'data': '*AB$i*', 'modules': 77}{'data': '*AB$I*', 'modules': 77}Failed
repair trap 1{'data': '*Z-9+X$i*', 'modules': 116}{'data': '*Z-9+X$I*', 'modules': 116}Failed
combined fault 2{'error': 'ratio'}{'error': 'ratio'}Passed
control 3{'error': 'ratio'}{'error': 'ratio'}Passed
control 4{'error': 'ratio'}{'error': 'ratio'}Passed
boundary 5{'char': 'a', 'error': 'char'}{'char': 'a', 'error': 'char'}Passed
boundary 6{'error': 'ratio'}{'error': 'ratio'}Passed
control 7{'data': '*$i/D5*', 'modules': 90}{'data': '*$I/D5*', 'modules': 90}Failed

SHA-256 / 3c4578846c3bbd2d508b90f971f37221dbbb6311453109303c7f1973eb259872

3 / The verified repair

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

N = 1
observations = []
def solve(text, mode, ratio):
    std = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%'
    if ratio not in (2, 3):
        return {'error': 'ratio'}
    if mode == 'standard':
        for ch in text:
            if ch not in std:
                return {'error': 'char', 'char': ch}
        enc = text
    else:
        punct = {'$': '/D', '%': '/E', '+': '/K', '/': '/O', '!': '/A', '"': '/B', '#': '/C', '&': '/F', "'": '/G',
                 '(': '/H', ')': '/I', '*': '/J', ',': '/L', ':': '/Z', ';': '%F', '<': '%G', '=': '%H', '>': '%I',
                 '?': '%J', '@': '%V', '[': '%K', '\\': '%L', ']': '%M', '^': '%N', '_': '%O', '`': '%W',
                 '{': '%P', '|': '%Q', '}': '%R', '~': '%S'}
        enc = ''
        for ch in text:
            o = ord(ch)
            if o > 127:
                return {'error': 'char', 'char': ch}
            if ch in punct:
                enc += punct[ch]
            elif 'a' <= ch <= 'z':
                enc += '+' + ch.upper()
            elif 1 <= o <= 26:
                enc += '$' + chr(o + 64)
            elif o == 0:
                enc += '%U'
            elif 27 <= o <= 31:
                enc += '%' + chr(o - 27 + 65)
            elif o == 127:
                enc += '%T'
            else:
                enc += ch
    count = len(enc) + 2
    return {'data': '*' + enc + '*', 'modules': count * (6 + 3 * ratio) + (count - 1)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[('AB\t', 'full', 2), {'data': '*AB$I*', 'modules': 77}], [('Z-9x\t', 'full', 2), {'data': '*Z-9+X$I*', 'modules': 116}], [('café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7PN/7', 'full', 1), {'error': 'ratio'}], [('a+ba+b', 'full', 4), {'error': 'ratio'}], [('Z-9a+blot', 'standard', 2), {'error': 'char', 'char': 'a'}], [('café\t', 'full', 4), {'error': 'ratio'}], [('\t$5', 'full', 2), {'data': '*$I/D5*', 'modules': 90}]], [[('\t#1', 'full', 2), {'data': '*$I/C1*', 'modules': 90}], [('\t\x1b', 'full', 2), {'data': '*$I%A*', 'modules': 77}], [('', 'standard', 1), {'error': 'ratio'}], [('\x1blotlot', 'full', 2), {'data': '*%A+L+O+T+L+O+T*', 'modules': 207}], [('#1', 'full', 2), {'data': '*/C1*', 'modules': 64}], [('ABa+b', 'full', 2), {'data': '*AB+A/K+B*', 'modules': 129}], [('', 'full', 3), {'data': '**', 'modules': 31}], [('\t', 'full', 3), {'data': '*$I*', 'modules': 63}]], [[('\t#1*', 'full', 3), {'data': '*$I/C1/J*', 'modules': 143}], [('\x7fq\t', 'full', 3), {'data': '*%T+Q$I*', 'modules': 127}], [('a+bAB', 'full', 2), {'data': '*+A/K+BAB*', 'modules': 129}], [('#1café', 'standard', 4), {'error': 'ratio'}], [('ABPN/7Z-9', 'full', 2), {'data': '*ABPN/O7Z-9*', 'modules': 155}], [(' ', 'full', 1), {'error': 'ratio'}], [('$5 \x00', 'full', 2), {'data': '*/D5 %U*', 'modules': 103}], [('\x00\t50%', 'full', 2), {'data': '*%U$I50/E*', 'modules': 129}]], [[('\t*q', 'full', 3), {'data': '*$I/J+Q*', 'modules': 127}], [('qPN/7café', 'full', 2), {'error': 'char', 'char': 'é'}], [('AB\x00 ', 'full', 1), {'error': 'ratio'}], [('*', 'full', 2), {'data': '*/J*', 'modules': 51}], [('AB12', 'standard', 2), {'data': '*AB12*', 'modules': 77}], [('#1café', 'full', 2), {'error': 'char', 'char': 'é'}], [(' ABPN/7', 'full', 1), {'error': 'ratio'}], [('\t\x7f', 'full', 3), {'data': '*$I%T*', 'modules': 95}]], [[('\t\t', 'full', 3), {'data': '*$I$I*', 'modules': 95}], [('  \t', 'full', 2), {'data': '*  $I*', 'modules': 77}], [('\x00', 'full', 1), {'error': 'ratio'}], [('', 'standard', 2), {'data': '**', 'modules': 25}], [('', 'standard', 1), {'error': 'ratio'}], [('\x7f\x00', 'full', 4), {'error': 'ratio'}], [('$5a+bAB', 'full', 3), {'data': '*/D5+A/K+BAB*', 'modules': 207}], [('50% \t', 'full', 3), {'data': '*50/E $I*', 'modules': 143}]]]
labels = ["regression: control character escape letter", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("%s %d" % (labels[i % len(labels)], i), 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: control character escape letter 0{'data': '*AB$I*', 'modules': 77}{'data': '*AB$I*', 'modules': 77}Passed
repair trap 1{'data': '*Z-9+X$I*', 'modules': 116}{'data': '*Z-9+X$I*', 'modules': 116}Passed
combined fault 2{'error': 'ratio'}{'error': 'ratio'}Passed
control 3{'error': 'ratio'}{'error': 'ratio'}Passed
control 4{'error': 'ratio'}{'error': 'ratio'}Passed
boundary 5{'char': 'a', 'error': 'char'}{'char': 'a', 'error': 'char'}Passed
boundary 6{'error': 'ratio'}{'error': 'ratio'}Passed
control 7{'data': '*$I/D5*', 'modules': 90}{'data': '*$I/D5*', 'modules': 90}Passed

SHA-256 / 8657e557ff263e68572805980af16dc58113812877ca377c97232ad424477848

Verification & scope

A deterministic bounded teaching model with a stipulated contract; it makes no claim of conformance to any published specification. 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:49:44.991058+00:00.

Case digest / 59786e514025d1ebe45c0b950d97bc576e4e7d18cc7b892193ab4f269988a9f3