A library for advanced Luhn algorithm operations
Project description
LuhnExtended
LuhnExtended is a Python library for advanced operations with the Luhn algorithm. It provides functions to generate, verify, and append Luhn check digits, with support for user-defined checksum values.
Features
- Checksum Calculation: Calculate the Luhn checksum for a given string of digits.
- Verification: Verify whether a string of digits satisfies the Luhn algorithm.
- Check Digit Generation: Generate the correct check digit to append to a string of digits.
- Append Check Digit: Easily append the correct Luhn check digit to a string.
Installation
Install the LuhnExtended library using pip directly from PyPI:
pip install LuhnExtended
Usage
Importing the Library
from LuhnExtended import checksum, verify, generate, append
Functions
checksum(string)
Compute the Luhn checksum for the provided string of digits. Note that this assumes the check digit is in place.
Example:
checksum_value = checksum("356938035643806")
print(checksum_value) # Output: 7
verify(string, checksum_expected=0)
Check if the provided string of digits satisfies the Luhn checksum.
Parameters:
string(str): The string of digits to verify.checksum_expected(int, optional): Expected checksum value.
Example:
# Test verification
is_valid = verify("356938035643806", 7)
print(f"Is ('356938035643806', 7) valid? {is_valid}") # Expected output: True
is_invalid = verify("356938035643806", 0)
print(f"Is ('356938035643806', 0) valid? {is_invalid}") # Expected output: False
is_invalid = verify("534618613411236", 7)
print(f"Is ('534618613411236', 7) valid? {is_invalid}") # Expected output: False
generate(string, checksum_desired=0)
Generate the Luhn check digit to append to the provided string.
Parameters:
string(str): The string of digits to generate a check digit for.checksum_desired(int, optional): Desired checksum value (default is0).
Example:
check_digit = generate("35693803564380", 7)
print(f"Generated check digit for ('35693803564380', 7): {check_digit}") # Output: 6
append(string, checksum_desired=0)
Append the Luhn check digit to the end of the provided string.
Parameters:
string(str): The string of digits to append a check digit to.checksum_desired(int, optional): Desired checksum value (default is0).
Example:
full_string = append("35693803564380", 7)
print(f"Appended check digit to ('35693803564380', 7): {full_string}") # Output: '356938035643806'
Author
Developed by Luhn Extended.
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file luhnextended-1.0.1.tar.gz.
File metadata
- Download URL: luhnextended-1.0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b528d678dbff43d690ce0a090c838c1c49d7d45b1ccf96d17605a8d8c9ea8630
|
|
| MD5 |
acc2296d5a44d3c0b2142342966c5fa1
|
|
| BLAKE2b-256 |
aa48bbad37b5fa3f1c67cd8f428ce61b9fe1cf2dafc3173a7fc223940ae654a9
|
File details
Details for the file LuhnExtended-1.0.1-py3-none-any.whl.
File metadata
- Download URL: LuhnExtended-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b7bf298762647be1764504edd50f2b9c62dc9f9da1eee8f9d30793bf1d736e0
|
|
| MD5 |
c7ec3849953145b692b03ba98e3cc633
|
|
| BLAKE2b-256 |
b3bdb6a475206cb51cabeb91e4554dae44a6047b62633859c6ffc428dfe218f8
|