stdnum.damm¶
The Damm algorithm.
The Damm algorithm is a check digit algorithm that should detect all single-digit errors and all adjacent transposition errors. Based on anti-symmetric quasigroup of order 10 it uses a substitution table.
This implementation uses the table from Wikipedia by default but a custom table can be provided.
More information:
>>> validate('572')
Traceback (most recent call last):
...
InvalidChecksum: ...
>>> calc_check_digit('572')
'4'
>>> validate('5724')
'5724'
>>> table = (
... (0, 2, 3, 4, 5, 6, 7, 8, 9, 1),
... (2, 0, 4, 1, 7, 9, 5, 3, 8, 6),
... (3, 7, 0, 5, 2, 8, 1, 6, 4, 9),
... (4, 1, 8, 0, 6, 3, 9, 2, 7, 5),
... (5, 6, 2, 9, 0, 7, 4, 1, 3, 8),
... (6, 9, 7, 3, 1, 0, 8, 5, 2, 4),
... (7, 5, 1, 8, 4, 2, 0, 9, 6, 3),
... (8, 4, 6, 2, 9, 5, 3, 0, 1, 7),
... (9, 8, 5, 7, 3, 1, 6, 4, 0, 2),
... (1, 3, 9, 6, 8, 4, 2, 7, 5, 0))
>>> checksum('816', table=table)
9
- stdnum.damm.calc_check_digit(number, table=None)¶
Calculate the extra digit that should be appended to the number to make it a valid number.
- stdnum.damm.checksum(number, table=None)¶
Calculate the Damm checksum over the provided number. The checksum is returned as an integer value and should be 0 when valid.
- stdnum.damm.is_valid(number, table=None)¶
Check if the number provided passes the Damm algorithm.
- stdnum.damm.validate(number, table=None)¶
Check if the number provided passes the Damm algorithm.