FA-72666 / Check-digit algorithms / Open access
UPC-E check is computed on the compressed digits · case 01
Valid UPC-E labels are rejected.
ROOT CAUSE
The weighted sum runs over the six compressed digits instead of the expanded 11-digit UPC-A.
VERIFIED REPAIR
Compute the check over number system plus the ten expanded body digits.
Unsuccessful approach: Summing the compressed digits with the number system still skips the inserted zeros positions.
Case contract
Expand an 8-digit UPC-E (number system 0 or 1, six compressed digits m1..m6, check digit) to UPC-A. By m6: 0-2 -> m1 m2 m6 0000 m3 m4 m5; 3 -> m1 m2 m3 00000 m4 m5; 4 -> m1 m2 m3 m4 00000 m5; 5-9 -> m1..m5 0000 m6. The UPC-A check (weights 3,1 from the left over the 11 digits) must equal the given check digit; return the 12-digit UPC-A string, or None for malformed or mismatching input.
Why this case matters
Point-of-sale systems normalise zero-suppressed UPC-E labels into UPC-A keys for price lookup.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(s):
if len(s) != 8 or not s.isascii() or not s.isdigit() or s[0] not in '01':
return None
ns, m, chk = s[0], s[1:7], s[7]
last = m[5]
if last in '012':
body = m[0:2] + last + '0000' + m[2:5]
elif last == '3':
body = m[0:3] + '00000' + m[3:5]
elif last == '4':
body = m[0:4] + '00000' + m[4]
else:
body = m[0:5] + '0000' + last
a = ns + body
total = sum(int(ch) * (3 if i % 2 == 0 else 1) for i, ch in enumerate(m))
check = (10 - total % 10) % 10
if str(check) != chk:
return None
return a + chk
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["13813703"]', ['13813703'], '138000001373'], ['regression ["08548229"]', ['08548229'], '085200004829'], ['partial-repair ["06109613"]', ['06109613'], '061100000963'], ['control ["03793961"]', ['03793961'], '037939000061'], ['control ["04896098"]', ['04896098'], '048960000098'], ['control ["28109420"]', ['28109420'], None], ['control ["32492194"]', ['32492194'], None], ['control ["73497295"]', ['73497295'], None]], [['regression ["10054749"]', ['10054749'], '100540000079'], ['regression ["08190253"]', ['08190253'], '081902000053'], ['partial-repair ["08639918"]', ['08639918'], '086100003998'], ['control ["97987994"]', ['97987994'], None], ['control ["23456781"]', ['23456781'], None], ['control ["0425261"]', ['0425261'], None], ['control ["0425261a"]', ['0425261a'], None], ['control ["04252615"]', ['04252615'], None]], [['regression ["00140485"]', ['00140485'], '001404000085'], ['regression ["14227004"]', ['14227004'], '142000002704'], ['partial-repair ["04793431"]', ['04793431'], '047900000341'], ['partial-repair ["07813340"]', ['07813340'], '078130000030'], ['control ["00000000"]', ['00000000'], '000000000000'], ['control ["03793961"]', ['03793961'], '037939000061'], ['control ["04896098"]', ['04896098'], '048960000098'], ['control ["28109420"]', ['28109420'], None]], [['regression ["14586929"]', ['14586929'], '145200008699'], ['regression ["04793431"]', ['04793431'], '047900000341'], ['partial-repair ["01234531"]', ['01234531'], '012300000451'], ['partial-repair ["06109613"]', ['06109613'], '061100000963'], ['control ["73497295"]', ['73497295'], None], ['control ["97987994"]', ['97987994'], None], ['control ["23456781"]', ['23456781'], None], ['control ["0425261"]', ['0425261'], None]], [['regression ["16526754"]', ['16526754'], '165267000054'], ['regression ["04252614"]', ['04252614'], '042100005264'], ['partial-repair ["03909633"]', ['03909633'], '039000000963'], ['partial-repair ["10054749"]', ['10054749'], '100540000079'], ['control ["04252615"]', ['04252615'], None], ['control ["00000000"]', ['00000000'], '000000000000'], ['control ["03793961"]', ['03793961'], '037939000061'], ['control ["04896098"]', ['04896098'], '048960000098']]]
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 ["13813703"] | None | 138000001373 | Failed |
| regression ["08548229"] | None | 085200004829 | Failed |
| partial-repair ["06109613"] | 061100000963 | 061100000963 | Passed |
| control ["03793961"] | 037939000061 | 037939000061 | Passed |
| control ["04896098"] | 048960000098 | 048960000098 | Passed |
| control ["28109420"] | None | None | Passed |
| control ["32492194"] | None | None | Passed |
| control ["73497295"] | None | None | Passed |
SHA-256 / 694dc59d5f6f5ec20bb6ae3bb8bf5ba92696882b18fc73dd4369317c1c2fee40
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(s):
if len(s) != 8 or not s.isascii() or not s.isdigit() or s[0] not in '01':
return None
ns, m, chk = s[0], s[1:7], s[7]
last = m[5]
if last in '012':
body = m[0:2] + last + '0000' + m[2:5]
elif last == '3':
body = m[0:3] + '00000' + m[3:5]
elif last == '4':
body = m[0:4] + '00000' + m[4]
else:
body = m[0:5] + '0000' + last
a = ns + body
total = sum(int(ch) * (3 if i % 2 == 0 else 1) for i, ch in enumerate(ns + m))
check = (10 - total % 10) % 10
if str(check) != chk:
return None
return a + chk
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["13813703"]', ['13813703'], '138000001373'], ['regression ["08548229"]', ['08548229'], '085200004829'], ['partial-repair ["06109613"]', ['06109613'], '061100000963'], ['control ["03793961"]', ['03793961'], '037939000061'], ['control ["04896098"]', ['04896098'], '048960000098'], ['control ["28109420"]', ['28109420'], None], ['control ["32492194"]', ['32492194'], None], ['control ["73497295"]', ['73497295'], None]], [['regression ["10054749"]', ['10054749'], '100540000079'], ['regression ["08190253"]', ['08190253'], '081902000053'], ['partial-repair ["08639918"]', ['08639918'], '086100003998'], ['control ["97987994"]', ['97987994'], None], ['control ["23456781"]', ['23456781'], None], ['control ["0425261"]', ['0425261'], None], ['control ["0425261a"]', ['0425261a'], None], ['control ["04252615"]', ['04252615'], None]], [['regression ["00140485"]', ['00140485'], '001404000085'], ['regression ["14227004"]', ['14227004'], '142000002704'], ['partial-repair ["04793431"]', ['04793431'], '047900000341'], ['partial-repair ["07813340"]', ['07813340'], '078130000030'], ['control ["00000000"]', ['00000000'], '000000000000'], ['control ["03793961"]', ['03793961'], '037939000061'], ['control ["04896098"]', ['04896098'], '048960000098'], ['control ["28109420"]', ['28109420'], None]], [['regression ["14586929"]', ['14586929'], '145200008699'], ['regression ["04793431"]', ['04793431'], '047900000341'], ['partial-repair ["01234531"]', ['01234531'], '012300000451'], ['partial-repair ["06109613"]', ['06109613'], '061100000963'], ['control ["73497295"]', ['73497295'], None], ['control ["97987994"]', ['97987994'], None], ['control ["23456781"]', ['23456781'], None], ['control ["0425261"]', ['0425261'], None]], [['regression ["16526754"]', ['16526754'], '165267000054'], ['regression ["04252614"]', ['04252614'], '042100005264'], ['partial-repair ["03909633"]', ['03909633'], '039000000963'], ['partial-repair ["10054749"]', ['10054749'], '100540000079'], ['control ["04252615"]', ['04252615'], None], ['control ["00000000"]', ['00000000'], '000000000000'], ['control ["03793961"]', ['03793961'], '037939000061'], ['control ["04896098"]', ['04896098'], '048960000098']]]
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 ["13813703"] | 138000001373 | 138000001373 | Passed |
| regression ["08548229"] | None | 085200004829 | Failed |
| partial-repair ["06109613"] | None | 061100000963 | Failed |
| control ["03793961"] | 037939000061 | 037939000061 | Passed |
| control ["04896098"] | 048960000098 | 048960000098 | Passed |
| control ["28109420"] | None | None | Passed |
| control ["32492194"] | None | None | Passed |
| control ["73497295"] | None | None | Passed |
SHA-256 / a0e47d58ce31b7e7199bf7e543ce5652de022d098f32dbdf10752ad6e388a8a4
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(s):
if len(s) != 8 or not s.isascii() or not s.isdigit() or s[0] not in '01':
return None
ns, m, chk = s[0], s[1:7], s[7]
last = m[5]
if last in '012':
body = m[0:2] + last + '0000' + m[2:5]
elif last == '3':
body = m[0:3] + '00000' + m[3:5]
elif last == '4':
body = m[0:4] + '00000' + m[4]
else:
body = m[0:5] + '0000' + last
a = ns + body
total = sum(int(ch) * (3 if i % 2 == 0 else 1) for i, ch in enumerate(a))
check = (10 - total % 10) % 10
if str(check) != chk:
return None
return a + chk
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["13813703"]', ['13813703'], '138000001373'], ['regression ["08548229"]', ['08548229'], '085200004829'], ['partial-repair ["06109613"]', ['06109613'], '061100000963'], ['control ["03793961"]', ['03793961'], '037939000061'], ['control ["04896098"]', ['04896098'], '048960000098'], ['control ["28109420"]', ['28109420'], None], ['control ["32492194"]', ['32492194'], None], ['control ["73497295"]', ['73497295'], None]], [['regression ["10054749"]', ['10054749'], '100540000079'], ['regression ["08190253"]', ['08190253'], '081902000053'], ['partial-repair ["08639918"]', ['08639918'], '086100003998'], ['control ["97987994"]', ['97987994'], None], ['control ["23456781"]', ['23456781'], None], ['control ["0425261"]', ['0425261'], None], ['control ["0425261a"]', ['0425261a'], None], ['control ["04252615"]', ['04252615'], None]], [['regression ["00140485"]', ['00140485'], '001404000085'], ['regression ["14227004"]', ['14227004'], '142000002704'], ['partial-repair ["04793431"]', ['04793431'], '047900000341'], ['partial-repair ["07813340"]', ['07813340'], '078130000030'], ['control ["00000000"]', ['00000000'], '000000000000'], ['control ["03793961"]', ['03793961'], '037939000061'], ['control ["04896098"]', ['04896098'], '048960000098'], ['control ["28109420"]', ['28109420'], None]], [['regression ["14586929"]', ['14586929'], '145200008699'], ['regression ["04793431"]', ['04793431'], '047900000341'], ['partial-repair ["01234531"]', ['01234531'], '012300000451'], ['partial-repair ["06109613"]', ['06109613'], '061100000963'], ['control ["73497295"]', ['73497295'], None], ['control ["97987994"]', ['97987994'], None], ['control ["23456781"]', ['23456781'], None], ['control ["0425261"]', ['0425261'], None]], [['regression ["16526754"]', ['16526754'], '165267000054'], ['regression ["04252614"]', ['04252614'], '042100005264'], ['partial-repair ["03909633"]', ['03909633'], '039000000963'], ['partial-repair ["10054749"]', ['10054749'], '100540000079'], ['control ["04252615"]', ['04252615'], None], ['control ["00000000"]', ['00000000'], '000000000000'], ['control ["03793961"]', ['03793961'], '037939000061'], ['control ["04896098"]', ['04896098'], '048960000098']]]
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 ["13813703"] | 138000001373 | 138000001373 | Passed |
| regression ["08548229"] | 085200004829 | 085200004829 | Passed |
| partial-repair ["06109613"] | 061100000963 | 061100000963 | Passed |
| control ["03793961"] | 037939000061 | 037939000061 | Passed |
| control ["04896098"] | 048960000098 | 048960000098 | Passed |
| control ["28109420"] | None | None | Passed |
| control ["32492194"] | None | None | Passed |
| control ["73497295"] | None | None | Passed |
SHA-256 / e3ecd1d841cae35b796765964997f9d4a28131a68b266feb598c0b0ee776d48e
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.488845+00:00.
Case digest / b51dcfd199bbe2cc1c6393e4e9e6e5fbff47acb2ad61ebbdc69204dc63954c41