Skip to content

bug: Japan Post check digit may use wrong modulus (mod 10 vs mod 19) #72

@productdevbook

Description

@productdevbook

Summary

The Japan Post 4-state barcode check digit in src/encoders/fourstate.ts uses modulo 10 on digit values, but some specifications indicate modulo 19 on bar state values should be used.

Details

Current code (mod 10 on digit values):

let sum = 0;
for (const ch of data) {
  sum += ch === "-" ? 10 : Number.parseInt(ch, 10);
}
data += ((10 - (sum % 10)) % 10).toString();

Japan Post specification reportedly uses:

Sum all the bar state values (each bar has a numeric value 1-4) across all data bars, then compute (19 - (sum % 19)) % 19 to get the check digit.

The distinction matters because:

  1. The modulus is different (10 vs 19)
  2. The input to the sum is different (character digit values vs bar state values)

Additional concern

The address encoding only accepts digits and dash (/^[\d-]+$/), but Japan Post barcodes can encode alphanumeric characters using control character prefixes (CC1-CC4). Letters A-Z are encoded as CC prefix + digit pair.

Verification needed

Cross-reference with the official Japan Post Customer Barcode Technical Specification and reference implementations (OkapiBarcode has a Java implementation).

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstandardsIndustry standard compliance

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions