Fast Luhn algorithm
Project description
Luhn-algorithm. Generate and validate strings of numbers. It is used for account number validation, credit card validation, data verification, cryptography, decoding, etcetera. Rust realization for speed-up python code. See benchmark for details.
- Author:
Matt Stroganov
- Version:
0.1.3
Installation
Install with pip:
$ pip install fast-luhn
Usage
Import package:
>>> import fast_luhn as fl
Validate
Check if string is valid by luhn algorithm. Return bool.
>>> fl.validate("471629309440")
False
Digit
Calculate next digit for string of numbers. Return int.
>>> fl.digit("47162930944")
7
Complete
Add luhn-check digit to string of numbers. Return string.
>>> fl.complete("2398560146")
'23985601469'
Generate
Generate luhn-valid string of numbers with length. Return string.
>>> fl.generate(50)
'58126333877729238938910323395262199130041545367401'
Build
Install from sources:
$ git clone https://github.com/cybermatt/fast-luhn $ cd fast-luhn $ pip install -r requirements-dev.txt $ python ./setup.py develop
Benchmark
Pure python realization (from here) was very slow.
Comparison with popular python Luhn modules:
method lib |
fast-luhn |
||
---|---|---|---|
validate |
4.65 µs |
13.3 µs |
0.2 µs |
generate |
48.1 µs |
94.4 µs |
3.17 µs |
Environment:
CPU i5-6500 3.20GHz, 16gb RAM
Linux 4.19
Python 3.7.3
Tests
$ pytest -v tests.py
License
This project is licensed under the MIT License - see the LICENSE.txt file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for fast_luhn-0.1.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea295b75834d2edff32937c864b1b78d6d0a3f21dc6de01fea239489e7f84e00 |
|
MD5 | 41d52a437c71959b1a937ed6d3cc1124 |
|
BLAKE2b-256 | 584de5db52bafdbf004f4a03cbd5064f66fb6159c87a350f38cfc36ca87dd870 |
Hashes for fast_luhn-0.1.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 544856c195592c65a48fef8a2b93458d884a42b8f2e6afe4561b337d57ff2e2c |
|
MD5 | c6c5a7118f87ec2735c02f8c36b2c6a5 |
|
BLAKE2b-256 | e65b39b4d858f435accecb11a8021a2b32b6cae0060b9be4f11fff42a3ee2f3f |
Hashes for fast_luhn-0.1.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd136accebd715f9300b1458a4d79984ae0cae7666e1774f85828dba2c0430b2 |
|
MD5 | 3dd9ee2d12bfa9e72c57ef5e1dd6b915 |
|
BLAKE2b-256 | dd3a4b9261241a6191d1b963bb2ac6952a20d5c32bdc0f697a5fde49e227b09d |
Hashes for fast_luhn-0.1.3-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28819db3dee6bf7cff2e22f046770f49adbed4bbc40533ce06c946fadc0e15d5 |
|
MD5 | 9ab2c7027a8ebba2b086e21460bcd1c2 |
|
BLAKE2b-256 | 1908a47c10f88041f115dae54d5598c14a8dadb774dccc791574752e2bc21fec |
Hashes for fast_luhn-0.1.3-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58e25f05fd8581c3caab8fad5983ac8185a12ec47d23aba5f56613b3addd9b10 |
|
MD5 | e8deb6e2f6e5a29c2cebb933f96b3eb9 |
|
BLAKE2b-256 | 6e0292c308481c1ed7a784975bc1dbeafe2eb0ef4a5e81f269e7911b7dbb4cd2 |