# stdnum.iso7064

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.

## Mod 11, 10

`stdnum.iso7064.mod_11_10`

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'

stdnum.iso7064.mod_11_10.calc_check_digit(number)

  Calculate the extra digit that should be appended to the number to make it a valid number.

stdnum.iso7064.mod_11_10.checksum(number)

  Calculate the checksum. A valid number should have a checksum of 1.

stdnum.iso7064.mod_11_10.is_valid(number)

  Check whether the check digit is valid.

stdnum.iso7064.mod_11_10.validate(number)

  Check whether the check digit is valid.

## Mod 11, 2

`stdnum.iso7064.mod_11_2`

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

stdnum.iso7064.mod_11_2.calc_check_digit(number)

  Calculate the extra digit that should be appended to the number to make it a valid number.

stdnum.iso7064.mod_11_2.checksum(number)

  Calculate the checksum. A valid number should have a checksum of 1.

stdnum.iso7064.mod_11_2.is_valid(number)

  Check whether the check digit is valid.

stdnum.iso7064.mod_11_2.validate(number)

  Check whether the check digit is valid.

## Mod 37, 2 (Mod x, 2)

`stdnum.iso7064.mod_37_2`

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

stdnum.iso7064.mod_37_2.calc_check_digit(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*')

  Calculate the extra digit that should be appended to the number to make it a valid number.

stdnum.iso7064.mod_37_2.checksum(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*')

  Calculate the checksum. A valid number should have a checksum of 1.

stdnum.iso7064.mod_37_2.is_valid(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*')

  Check whether the check digit is valid.

stdnum.iso7064.mod_37_2.validate(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*')

  Check whether the check digit is valid.

## Mod 37, 36 (Mod x+1, x)

`stdnum.iso7064.mod_37_36`

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'

stdnum.iso7064.mod_37_36.calc_check_digit(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')

  Calculate the extra digit that should be appended to the number to make it a valid number.

stdnum.iso7064.mod_37_36.checksum(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')

  Calculate the checksum. A valid number should have a checksum of 1.

stdnum.iso7064.mod_37_36.is_valid(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')

  Check whether the check digit is valid.

stdnum.iso7064.mod_37_36.validate(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')

  Check whether the check digit is valid.

## Mod 97, 10

`stdnum.iso7064.mod_97_10`

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'

stdnum.iso7064.mod_97_10.calc_check_digits(number)

  Calculate the extra digits that should be appended to the number to make it a valid number.

stdnum.iso7064.mod_97_10.checksum(number)

  Calculate the checksum. A valid number should have a checksum of 1.

stdnum.iso7064.mod_97_10.is_valid(number)

  Check whether the check digit is valid.

stdnum.iso7064.mod_97_10.validate(number)

  Check whether the check digit is valid.