FA-72756 / Check-digit algorithms / Open access
Amex prefix test uses a range · case 01
Diners-style 35 and 36 prefixes with 15 digits are routed to amex.
ROOT CAUSE
The prefix test is a string range 34..37 instead of the two exact prefixes.
THE FAILURE
The prefix test is a string range 34..37 instead of the two exact prefixes.
Unsuccessful approach: Accepting only 37 drops every 34-prefixed card.
Case contract
Card number screening: spaces removed, nonempty ASCII digits required (else "malformed"). Network by prefix and length: visa 4 with 13/16/19 digits; amex 34 or 37 with 15; mastercard 51-55 or 2221-2720 with 16; discover 6011, 644-649 or 65 with 16-19; otherwise "unknown". Return [network, Luhn validity].
Why this case matters
Checkout forms route card numbers to the right processor and reject Luhn failures before authorization.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(s):
t = s.replace(' ', '')
if not t or not t.isascii() or not t.isdigit():
return 'malformed'
n = len(t)
if t[0] == '4' and n in (13, 16, 19):
net = 'visa'
elif '34' <= t[:2] <= '37' and n == 15:
net = 'amex'
elif (51 <= int(t[:2]) <= 55 or 2221 <= int(t[:4]) <= 2720) and n == 16:
net = 'mastercard'
elif (t[:4] == '6011' or 644 <= int(t[:3]) <= 649 or t[:2] == '65') and 16 <= n <= 19:
net = 'discover'
else:
net = 'unknown'
total = 0
for i, ch in enumerate(reversed(t)):
d = int(ch) * (2 if i % 2 else 1)
total += d - 9 if d > 9 else d
return [net, total % 10 == 0]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["351552971521401"]', ['351552971521401'], ['unknown', True]], ['regression ["367788575584486"]', ['367788575584486'], ['unknown', False]], ['partial-repair ["341466066267172"]', ['341466066267172'], ['amex', False]], ['control ["4846348185497646"]', ['4846348185497646'], ['visa', False]], ['control ["4677178611987"]', ['4677178611987'], ['visa', False]], ['control ["4654355756337734313"]', ['4654355756337734313'], ['visa', False]], ['control ["376431358491919"]', ['376431358491919'], ['amex', False]], ['control ["5168420993367718"]', ['5168420993367718'], ['mastercard', False]]], [['regression ["367788575584486"]', ['367788575584486'], ['unknown', False]], ['regression ["351552971521401"]', ['351552971521401'], ['unknown', True]], ['partial-repair ["341466066267172"]', ['341466066267172'], ['amex', False]], ['control ["5518245380112330"]', ['5518245380112330'], ['mastercard', False]], ['control ["5656984207856782"]', ['5656984207856782'], ['unknown', False]], ['control ["2221631854572594"]', ['2221631854572594'], ['mastercard', False]], ['control ["2720611269032342"]', ['2720611269032342'], ['mastercard', False]], ['control ["2721101650461399"]', ['2721101650461399'], ['unknown', False]]], [['regression ["351552971521401"]', ['351552971521401'], ['unknown', True]], ['regression ["367788575584486"]', ['367788575584486'], ['unknown', False]], ['partial-repair ["341466066267172"]', ['341466066267172'], ['amex', False]], ['control ["2719349847162292"]', ['2719349847162292'], ['mastercard', False]], ['control ["6011388299412119"]', ['6011388299412119'], ['discover', False]], ['control ["6441839750335463"]', ['6441839750335463'], ['discover', False]], ['control ["6490399248434857177"]', ['6490399248434857177'], ['discover', False]], ['control ["6408243514832764"]', ['6408243514832764'], ['unknown', False]]], [['regression ["367788575584486"]', ['367788575584486'], ['unknown', False]], ['regression ["351552971521401"]', ['351552971521401'], ['unknown', True]], ['partial-repair ["341466066267172"]', ['341466066267172'], ['amex', False]], ['control ["6438800916518222"]', ['6438800916518222'], ['unknown', False]], ['control ["65813918194527509"]', ['65813918194527509'], ['discover', False]], ['control ["6692677811687578"]', ['6692677811687578'], ['unknown', True]], ['control ["4111 1111 1111 1111"]', ['4111 1111 1111 1111'], ['visa', True]], ['control ["378282246310005"]', ['378282246310005'], ['amex', True]]], [['regression ["351552971521401"]', ['351552971521401'], ['unknown', True]], ['regression ["367788575584486"]', ['367788575584486'], ['unknown', False]], ['partial-repair ["341466066267172"]', ['341466066267172'], ['amex', False]], ['control ["5555555555554444"]', ['5555555555554444'], ['mastercard', True]], ['control ["2223003122003222"]', ['2223003122003222'], ['mastercard', True]], ['control ["6011111111111117"]', ['6011111111111117'], ['discover', True]], ['control ["4111-1111"]', ['4111-1111'], 'malformed'], ['control [""]', [''], 'malformed']]]
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 ["351552971521401"] | ['amex', True] | ['unknown', True] | Failed |
| regression ["367788575584486"] | ['amex', False] | ['unknown', False] | Failed |
| partial-repair ["341466066267172"] | ['amex', False] | ['amex', False] | Passed |
| control ["4846348185497646"] | ['visa', False] | ['visa', False] | Passed |
| control ["4677178611987"] | ['visa', False] | ['visa', False] | Passed |
| control ["4654355756337734313"] | ['visa', False] | ['visa', False] | Passed |
| control ["376431358491919"] | ['amex', False] | ['amex', False] | Passed |
| control ["5168420993367718"] | ['mastercard', False] | ['mastercard', False] | Passed |
SHA-256 / c93c6a0b0d0066c8cf28eb8ab533e5d1784acca39e691f983d8baf1c782a2efc
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(s):
t = s.replace(' ', '')
if not t or not t.isascii() or not t.isdigit():
return 'malformed'
n = len(t)
if t[0] == '4' and n in (13, 16, 19):
net = 'visa'
elif t[:2] == '37' and n == 15:
net = 'amex'
elif (51 <= int(t[:2]) <= 55 or 2221 <= int(t[:4]) <= 2720) and n == 16:
net = 'mastercard'
elif (t[:4] == '6011' or 644 <= int(t[:3]) <= 649 or t[:2] == '65') and 16 <= n <= 19:
net = 'discover'
else:
net = 'unknown'
total = 0
for i, ch in enumerate(reversed(t)):
d = int(ch) * (2 if i % 2 else 1)
total += d - 9 if d > 9 else d
return [net, total % 10 == 0]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression ["351552971521401"]', ['351552971521401'], ['unknown', True]], ['regression ["367788575584486"]', ['367788575584486'], ['unknown', False]], ['partial-repair ["341466066267172"]', ['341466066267172'], ['amex', False]], ['control ["4846348185497646"]', ['4846348185497646'], ['visa', False]], ['control ["4677178611987"]', ['4677178611987'], ['visa', False]], ['control ["4654355756337734313"]', ['4654355756337734313'], ['visa', False]], ['control ["376431358491919"]', ['376431358491919'], ['amex', False]], ['control ["5168420993367718"]', ['5168420993367718'], ['mastercard', False]]], [['regression ["367788575584486"]', ['367788575584486'], ['unknown', False]], ['regression ["351552971521401"]', ['351552971521401'], ['unknown', True]], ['partial-repair ["341466066267172"]', ['341466066267172'], ['amex', False]], ['control ["5518245380112330"]', ['5518245380112330'], ['mastercard', False]], ['control ["5656984207856782"]', ['5656984207856782'], ['unknown', False]], ['control ["2221631854572594"]', ['2221631854572594'], ['mastercard', False]], ['control ["2720611269032342"]', ['2720611269032342'], ['mastercard', False]], ['control ["2721101650461399"]', ['2721101650461399'], ['unknown', False]]], [['regression ["351552971521401"]', ['351552971521401'], ['unknown', True]], ['regression ["367788575584486"]', ['367788575584486'], ['unknown', False]], ['partial-repair ["341466066267172"]', ['341466066267172'], ['amex', False]], ['control ["2719349847162292"]', ['2719349847162292'], ['mastercard', False]], ['control ["6011388299412119"]', ['6011388299412119'], ['discover', False]], ['control ["6441839750335463"]', ['6441839750335463'], ['discover', False]], ['control ["6490399248434857177"]', ['6490399248434857177'], ['discover', False]], ['control ["6408243514832764"]', ['6408243514832764'], ['unknown', False]]], [['regression ["367788575584486"]', ['367788575584486'], ['unknown', False]], ['regression ["351552971521401"]', ['351552971521401'], ['unknown', True]], ['partial-repair ["341466066267172"]', ['341466066267172'], ['amex', False]], ['control ["6438800916518222"]', ['6438800916518222'], ['unknown', False]], ['control ["65813918194527509"]', ['65813918194527509'], ['discover', False]], ['control ["6692677811687578"]', ['6692677811687578'], ['unknown', True]], ['control ["4111 1111 1111 1111"]', ['4111 1111 1111 1111'], ['visa', True]], ['control ["378282246310005"]', ['378282246310005'], ['amex', True]]], [['regression ["351552971521401"]', ['351552971521401'], ['unknown', True]], ['regression ["367788575584486"]', ['367788575584486'], ['unknown', False]], ['partial-repair ["341466066267172"]', ['341466066267172'], ['amex', False]], ['control ["5555555555554444"]', ['5555555555554444'], ['mastercard', True]], ['control ["2223003122003222"]', ['2223003122003222'], ['mastercard', True]], ['control ["6011111111111117"]', ['6011111111111117'], ['discover', True]], ['control ["4111-1111"]', ['4111-1111'], 'malformed'], ['control [""]', [''], 'malformed']]]
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 ["351552971521401"] | ['unknown', True] | ['unknown', True] | Passed |
| regression ["367788575584486"] | ['unknown', False] | ['unknown', False] | Passed |
| partial-repair ["341466066267172"] | ['unknown', False] | ['amex', False] | Failed |
| control ["4846348185497646"] | ['visa', False] | ['visa', False] | Passed |
| control ["4677178611987"] | ['visa', False] | ['visa', False] | Passed |
| control ["4654355756337734313"] | ['visa', False] | ['visa', False] | Passed |
| control ["376431358491919"] | ['amex', False] | ['amex', False] | Passed |
| control ["5168420993367718"] | ['mastercard', False] | ['mastercard', False] | Passed |
SHA-256 / e242ed875299c94fe7b5a1951d1faccd9a8612daece20701dbab52df934956f8
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:41.329190+00:00.
Case digest / c19dc73a740040d1684364693a69e23b3a7a9565f9814e309067b743c0cf8fa6