Generalized Luhn algorithm to any numerical base
Luhn algorithm is described in Annex B of ISO/IEC 7812-1:2017. As it is described at Luhn's Wikipedia page, the algorithm is used to compute check digits and check them in identification numbers, like the usually found in credit card numbers. The standard algorithm uses 10 as numeric base for the check digit.
But there are other scenarios, like nih URIs at IETF RFC 6920, where the numeric base of the check digit to be computed and validated is 16 (see examples at section 8.2 of RFC 6920).
This library is just an implementation of the algorithm for any base. There are two methods, compute and validate, which take as first parameter either an integer, or a string representing the number in the base, or an array of integers, where the value of each position is the corresponding numeric digit. compute method computes the check digit, meanwhile validate takes the whole identification number, the numerical base and the check digit, and answers either True or False.
genluhn.compute('5326-9057-e12f-e2b7-4ba0-7c89-2560-a2',16)
# It return 15
genluhn.validate('5326-9057-e12f-e2b7-4ba0-7c89-2560-a2', 16, 15)
# It returns True
genluhn.validate('5326-9057-e12f-e2b7-4ba0-7c89-2560-a2', 16, 14)
# It returns False
Accessory methods of this library are intToDigits, strToDigits and bytesToDigits, which are used when either an integer, or a string or a byteslike object have to be translated to a list of digits in the given numerical base.
Metadata
Release files for genluhn 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| genluhn-0.3.1.tar.gz | 13.6 kB | Without provenance | Details for genluhn-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| genluhn-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for genluhn-0.3.1-py3-none-any.whl |
Total release size: 27.6 kB
Release files / genluhn-0.3.1.tar.gz
| Download URL | genluhn-0.3.1.tar.gz |
|---|---|
| Size | 13.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a92a158501a23c9e951e61e227a3bb7952b352ea85e2c3d979b0883c2f6782b5
|
|
BLAKE2b-256 checksum How to use checksums |
a869bc22c70131f1d63c08a6f9e6673579d764579764f3d82675a46ca29f3dc6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Release files / genluhn-0.3.1-py3-none-any.whl
| Download URL | genluhn-0.3.1-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd7e12e9f0a4cbe12d3a2e153d6363901cf0318eda64fa64122360fb47b4b73b
|
|
BLAKE2b-256 checksum How to use checksums |
a7cbc85fab03018d425f4b5ecf6c4d86994ab2fb2cfa6d53cbd3cd0c2536c50a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Security for genluhn 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.