Collection of the ISO 7064 algorithms.
This package provides a number of modules for calculation and verification of numbers using one of the ISO 7064 algorithms.
Note that these functions were not implemented using the ISO text itself because the text is not available for free. These functions were implemented based on information on the algorithms found online and some reverse engineering. If anyone can provide a legal copy of the ISO/IEC 7064 standard these functions can be validated and perhaps improved.
The ISO 7064 Mod 11, 10 algorithm.
The Mod 11, 10 algorithm uses a number of calculations modulo 11 and 10 to determine a checksum.
For a module that can do generic Mod x+1, x calculations see the stdnum.iso7064.mod_37_36 module.
>>> calc_check_digit('79462')
'3'
>>> validate('794623')
'794623'
>>> calc_check_digit('00200667308')
'5'
>>> validate('002006673085')
'002006673085'
With the provided number, calculate the extra digit that should be appended to make it a valid number.
Calculate the checksum. A valid number should have a checksum of 1.
Checks whether the check digit is valid.
Checks whether the check digit is valid.
The ISO 7064 Mod 11, 2 algorithm.
The Mod 11, 2 algorithm is a simple module 11 checksum where the check digit can be an X to make the number valid.
For a module that can do generic Mod x, 2 calculations see the stdnum.iso7064.mod_37_2 module.
>>> calc_check_digit('0794')
'0'
>>> validate('07940')
'07940'
>>> calc_check_digit('079')
'X'
>>> validate('079X')
'079X'
>>> checksum('079X')
1
With the provided number, calculate the extra digit that should be appended to make it a valid number.
Calculate the checksum. A valid number should have a checksum of 1.
Checks whether the check digit is valid.
Checks whether the check digit is valid.
The ISO 7064 Mod 37, 2 algorithm.
The Mod 37, 2 checksum can be used for alphanumeric numbers and the check digit may also be numeric, a letter or ‘*’.
>>> calc_check_digit('G123489654321')
'Y'
>>> validate('G123489654321Y')
'G123489654321Y'
>>> checksum('G123489654321Y')
1
By changing the alphabet this can be turned into any Mod x, 2 algorithm. For example Mod 11, 2:
>>> calc_check_digit('079', alphabet='0123456789X')
'X'
>>> validate('079X', alphabet='0123456789X')
'079X'
>>> checksum('079X', alphabet='0123456789X')
1
With the provided number, calculate the extra digit that should be appended to make it a valid number.
Calculate the checksum. A valid number should have a checksum of 1.
Checks whether the check digit is valid.
Checks whether the check digit is valid.
The ISO 7064 Mod 37, 36 algorithm.
The Mod 37, 36 algorithm uses an alphanumeric check digit and the number itself may also contain letters.
>>> checksum('A12425GABC1234002M')
1
>>> calc_check_digit('A12425GABC1234002')
'M'
>>> validate('A12425GABC1234002M')
'A12425GABC1234002M'
By changing the alphabet this can be turned into any Mod x+1, x algorithm. For example Mod 11, 10:
>>> calc_check_digit('00200667308', alphabet='0123456789')
'5'
>>> validate('002006673085', alphabet='0123456789')
'002006673085'
With the provided number, calculate the extra digit that should be appended to make it a valid number.
Calculate the checksum. A valid number should have a checksum of 1.
Checks whether the check digit is valid.
Checks whether the check digit is valid.
The ISO 7064 Mod 97, 10 algorithm.
The Mod 97, 10 algorithm evaluates the whole number as an integer which is valid if the number modulo 97 is 1. As such it has two check digits.
>>> calc_check_digits('99991234567890121414')
'90'
>>> validate('9999123456789012141490')
'9999123456789012141490'
>>> calc_check_digits('4354111611551114')
'31'
>>> validate('08686001256515001121751')
'08686001256515001121751'
>>> calc_check_digits('22181321402534321446701611')
'35'
With the provided number, calculate the extra digits that should be appended to make it a valid number.
Calculate the checksum. A valid number should have a checksum of 1.
Checks whether the check digit is valid.
Checks whether the check digit is valid.