hashes.luhn

Luhn Algorithm

Functions

is_luhn(→ bool)

Perform Luhn validation on an input string

Module Contents

hashes.luhn.is_luhn(string: str) bool

Perform Luhn validation on an input string Algorithm: * Double every other digit starting from 2nd last digit. * Subtract 9 if number is greater than 9. * Sum the numbers * >>> test_cases = (79927398710, 79927398711, 79927398712, 79927398713, … 79927398714, 79927398715, 79927398716, 79927398717, 79927398718, … 79927398719) >>> [is_luhn(str(test_case)) for test_case in test_cases] [False, False, False, True, False, False, False, False, False, False]