Skip to content

Commit b07b417

Browse files
authored
Merge pull request #325 from Integration-Automation/feat/checksum-batch
Add check-digit algorithms (Luhn, Verhoeff, Damm, ISO 7064 MOD 97-10)
2 parents 3e675ed + 390f8ab commit b07b417

15 files changed

Lines changed: 425 additions & 1 deletion

File tree

README/WHATS_NEW_zh-CN.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# 本次更新 — AutoControl
22

3+
## 本次更新 (2026-06-22) — 校验位算法
4+
5+
计算/验证 Luhn、Verhoeff、Damm 与 ISO 7064 MOD 97-10 校验位。完整参考:[`docs/source/Zh/doc/new_features/v115_features_doc.rst`](../docs/source/Zh/doc/new_features/v115_features_doc.rst)
6+
7+
- **`luhn_validate` / `luhn_check_digit` / `verhoeff_*` / `damm_*` / `mod97_10_*`**(`AC_checksum_validate``AC_checksum_digit`):`pii_text` 以正则检测卡号/IBAN 形状、`data_quality` 做正则验证,但没有任何功能计算或验证*校验位*。本功能加入多数标识符背后的四种方案(卡号/IMEI、身份证号、IBAN)——`identifier_validate` 所依据的共用引擎。纯标准库、确定。
8+
39
## 本次更新 (2026-06-22) — 移动平均平滑
410

511
平滑噪声值序列。完整参考:[`docs/source/Zh/doc/new_features/v102_features_doc.rst`](../docs/source/Zh/doc/new_features/v102_features_doc.rst)

README/WHATS_NEW_zh-TW.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# 本次更新 — AutoControl
22

3+
## 本次更新 (2026-06-22) — 檢查碼演算法
4+
5+
計算/驗證 Luhn、Verhoeff、Damm 與 ISO 7064 MOD 97-10 檢查碼。完整參考:[`docs/source/Zh/doc/new_features/v115_features_doc.rst`](../docs/source/Zh/doc/new_features/v115_features_doc.rst)
6+
7+
- **`luhn_validate` / `luhn_check_digit` / `verhoeff_*` / `damm_*` / `mod97_10_*`**(`AC_checksum_validate``AC_checksum_digit`):`pii_text` 以正則偵測卡號/IBAN 形狀、`data_quality` 做正則驗證,但沒有任何功能計算或驗證*檢查碼*。本功能加入多數識別碼背後的四種方案(卡號/IMEI、國民身分碼、IBAN)——`identifier_validate` 所依據的共用引擎。純標準函式庫、具決定性。
8+
39
## 本次更新 (2026-06-22) — 移動平均平滑
410

511
平滑雜訊值序列。完整參考:[`docs/source/Zh/doc/new_features/v102_features_doc.rst`](../docs/source/Zh/doc/new_features/v102_features_doc.rst)

WHATS_NEW.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# What's New — AutoControl
22

3+
## What's new (2026-06-22) — Check-Digit Algorithms
4+
5+
Compute / verify Luhn, Verhoeff, Damm and ISO 7064 MOD 97-10 check digits. Full reference: [`docs/source/Eng/doc/new_features/v115_features_doc.rst`](docs/source/Eng/doc/new_features/v115_features_doc.rst).
6+
7+
- **`luhn_validate` / `luhn_check_digit` / `verhoeff_*` / `damm_*` / `mod97_10_*`** (`AC_checksum_validate`, `AC_checksum_digit`): `pii_text` detects card/IBAN shapes by regex and `data_quality` does regex validation, but nothing computed or verified a *check digit*. This adds the four schemes behind most identifiers (cards/IMEI, national IDs, IBAN) — the shared engine `identifier_validate` builds on. Pure-stdlib, deterministic.
8+
39
## What's new (2026-06-22) — GNU gettext Catalog I/O (.po / .mo)
410

511
Read/compile the de-facto translation format. Full reference: [`docs/source/Eng/doc/new_features/v114_features_doc.rst`](docs/source/Eng/doc/new_features/v114_features_doc.rst).
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Check-Digit Algorithms
2+
======================
3+
4+
``pii_text`` detects credit-card and IBAN *shapes* by regex and ``data_quality``
5+
does type / range / regex validation, but nothing actually computes or verifies a
6+
*check digit*. This adds the shared arithmetic engine for the four schemes behind
7+
most real-world identifiers — and the primitive that account-number, card, IBAN,
8+
ISBN and EAN validation build on.
9+
10+
Pure standard library (integer arithmetic; the Verhoeff and Damm tables are small
11+
embedded constants). Every function is pure (string in, bool / str out), so it is
12+
fully deterministic in CI.
13+
14+
Headless API
15+
------------
16+
17+
.. code-block:: python
18+
19+
from je_auto_control import (
20+
luhn_validate, luhn_check_digit,
21+
verhoeff_validate, verhoeff_check_digit,
22+
damm_validate, damm_check_digit,
23+
mod97_10_validate, mod97_10_check_digits,
24+
)
25+
26+
luhn_validate("4111111111111111") # True (credit-card / IMEI)
27+
luhn_check_digit("7992739871") # '3' -> 79927398713
28+
verhoeff_validate("2363") # True (catches transpositions)
29+
damm_check_digit("572") # '4'
30+
mod97_10_validate("3214282912345698765432161182") # True (IBAN engine)
31+
32+
- **Luhn** (mod 10): credit cards, IMEI, many national IDs — catches all
33+
single-digit errors and most adjacent transpositions.
34+
- **Verhoeff** and **Damm**: decimal schemes that catch *all* single-digit and
35+
adjacent-transposition errors (stronger than Luhn).
36+
- **ISO 7064 MOD 97-10**: the two-check-digit scheme behind IBAN and similar.
37+
38+
Each scheme exposes ``*_validate(number)`` (does the value incl. its check digit
39+
verify?) and ``*_check_digit`` / ``*_check_digits`` (what digit(s) to append to a
40+
bare payload?). Non-digit characters are ignored, so spaced/grouped input works.
41+
42+
Executor commands
43+
-----------------
44+
45+
``AC_checksum_validate`` takes a ``scheme`` (``luhn`` / ``verhoeff`` / ``damm`` /
46+
``mod97``) plus a ``number`` and returns ``{valid}``; ``AC_checksum_digit`` returns
47+
``{check_digit}`` for a ``partial``. Both are exposed as MCP tools
48+
(``ac_checksum_validate`` / ``ac_checksum_digit``) and as Script Builder commands
49+
under **Data**.

docs/source/Eng/eng_index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Comprehensive guides for all AutoControl features.
137137
doc/new_features/v112_features_doc
138138
doc/new_features/v113_features_doc
139139
doc/new_features/v114_features_doc
140+
doc/new_features/v115_features_doc
140141
doc/ocr_backends/ocr_backends_doc
141142
doc/observability/observability_doc
142143
doc/operations_layer/operations_layer_doc
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
檢查碼演算法
2+
============
3+
4+
``pii_text`` 以正則偵測信用卡與 IBAN 的*形狀*、``data_quality`` 做型別/範圍/正則驗證,但沒有任何功能實際
5+
計算或驗證*檢查碼*。本功能加入多數真實世界識別碼背後四種方案的共用運算引擎——也是帳號、卡號、IBAN、
6+
ISBN、EAN 驗證所依據的基本元件。
7+
8+
純標準函式庫(整數運算;Verhoeff 與 Damm 表為小型內嵌常數)。每個函式皆為純函式(字串進、bool/str 出),
9+
因此在 CI 中完全具決定性。
10+
11+
無頭 API
12+
--------
13+
14+
.. code-block:: python
15+
16+
from je_auto_control import (
17+
luhn_validate, luhn_check_digit,
18+
verhoeff_validate, verhoeff_check_digit,
19+
damm_validate, damm_check_digit,
20+
mod97_10_validate, mod97_10_check_digits,
21+
)
22+
23+
luhn_validate("4111111111111111") # True (信用卡 / IMEI)
24+
luhn_check_digit("7992739871") # '3' -> 79927398713
25+
verhoeff_validate("2363") # True (可抓出換位錯誤)
26+
damm_check_digit("572") # '4'
27+
mod97_10_validate("3214282912345698765432161182") # True (IBAN 引擎)
28+
29+
- **Luhn**(mod 10):信用卡、IMEI、多種國民身分碼——可抓出所有單一數字錯誤與多數相鄰換位。
30+
- **Verhoeff** 與 **Damm**:十進位方案,可抓出*所有*單一數字與相鄰換位錯誤(比 Luhn 更強)。
31+
- **ISO 7064 MOD 97-10**:IBAN 等使用的雙檢查碼方案。
32+
33+
每個方案提供 ``*_validate(number)``(含檢查碼的值是否驗證通過?)與 ``*_check_digit`` / ``*_check_digits``
34+
(對裸負載應附加哪些檢查碼?)。非數字字元會被忽略,因此含空格/分組的輸入也適用。
35+
36+
執行器命令
37+
----------
38+
39+
``AC_checksum_validate`` 接受 ``scheme``(``luhn`` / ``verhoeff`` / ``damm`` / ``mod97``)與 ``number`` 並回傳
40+
``{valid}``;``AC_checksum_digit`` 對 ``partial`` 回傳 ``{check_digit}``。兩者皆以 MCP 工具
41+
(``ac_checksum_validate`` / ``ac_checksum_digit``)以及 Script Builder 中 **Data** 分類下的命令提供。

docs/source/Zh/zh_index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ AutoControl 所有功能的完整使用指南。
137137
doc/new_features/v112_features_doc
138138
doc/new_features/v113_features_doc
139139
doc/new_features/v114_features_doc
140+
doc/new_features/v115_features_doc
140141
doc/ocr_backends/ocr_backends_doc
141142
doc/observability/observability_doc
142143
doc/operations_layer/operations_layer_doc

je_auto_control/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@
245245
from je_auto_control.utils.gettext_catalog import (
246246
GettextCatalog, parse_po, parse_po_file, read_mo, read_mo_file,
247247
)
248+
# Check-digit algorithms (Luhn / Verhoeff / Damm / ISO 7064 MOD 97-10)
249+
from je_auto_control.utils.checksum import (
250+
damm_check_digit, damm_validate, luhn_check_digit, luhn_validate,
251+
mod97_10_check_digits, mod97_10_validate, verhoeff_check_digit,
252+
verhoeff_validate,
253+
)
248254
# CI workflow annotations (GitHub Actions)
249255
from je_auto_control.utils.ci_annotations import (
250256
emit_annotations, format_annotation,
@@ -1007,6 +1013,14 @@ def start_autocontrol_gui(*args, **kwargs):
10071013
"parse_po_file",
10081014
"read_mo",
10091015
"read_mo_file",
1016+
"luhn_validate",
1017+
"luhn_check_digit",
1018+
"verhoeff_validate",
1019+
"verhoeff_check_digit",
1020+
"damm_validate",
1021+
"damm_check_digit",
1022+
"mod97_10_validate",
1023+
"mod97_10_check_digits",
10101024
"emit_annotations", "format_annotation",
10111025
"ClipboardHistory", "default_clipboard_history",
10121026
"analyze_heal_log", "heal_stats", "scan_secrets",

je_auto_control/gui/script_builder/command_schema.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,24 @@ def _add_resilience_specs(specs: List[CommandSpec]) -> None:
21702170
),
21712171
description="Pick the plural-correct translation for count n.",
21722172
))
2173+
specs.append(CommandSpec(
2174+
"AC_checksum_validate", "Data", "Checksum: Validate",
2175+
fields=(
2176+
FieldSpec("scheme", FieldType.STRING,
2177+
placeholder="luhn | verhoeff | damm | mod97"),
2178+
FieldSpec("number", FieldType.STRING, placeholder="4111111111111111"),
2179+
),
2180+
description="Validate a number's check digit (Luhn/Verhoeff/Damm/mod97).",
2181+
))
2182+
specs.append(CommandSpec(
2183+
"AC_checksum_digit", "Data", "Checksum: Check Digit",
2184+
fields=(
2185+
FieldSpec("scheme", FieldType.STRING,
2186+
placeholder="luhn | verhoeff | damm | mod97"),
2187+
FieldSpec("partial", FieldType.STRING, placeholder="799273987"),
2188+
),
2189+
description="Compute the check digit(s) to append to a value.",
2190+
))
21732191
specs.append(CommandSpec(
21742192
"AC_diff_rows", "Data", "Dataset Diff: Rows by Key",
21752193
fields=(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Check-digit algorithms: Luhn, Verhoeff, Damm, ISO 7064 MOD 97-10."""
2+
from je_auto_control.utils.checksum.checksum import (
3+
damm_check_digit, damm_validate, luhn_check_digit, luhn_validate,
4+
mod97_10_check_digits, mod97_10_validate, verhoeff_check_digit,
5+
verhoeff_validate,
6+
)
7+
8+
__all__ = [
9+
"damm_check_digit", "damm_validate", "luhn_check_digit", "luhn_validate",
10+
"mod97_10_check_digits", "mod97_10_validate", "verhoeff_check_digit",
11+
"verhoeff_validate",
12+
]

0 commit comments

Comments
 (0)