Skip to main content

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 is 0).

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 is 0).

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

luhnextended-1.0.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

LuhnExtended-1.0.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file luhnextended-1.0.0.tar.gz.

File metadata

  • Download URL: luhnextended-1.0.0.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

Hashes for luhnextended-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5182a74efe939d3a564b02c02320ff1accf06a2b5bca95b51290f4a5250abc67
MD5 5571c64ce5838fca591c5bae10a3c2fa
BLAKE2b-256 7d5cc7ff0a5cd37bd676179b44fc0aa90777247c0f7b8dd957e678b3753ac7a1

See more details on using hashes here.

File details

Details for the file LuhnExtended-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: LuhnExtended-1.0.0-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

Hashes for LuhnExtended-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 795a7aa27d0e505b1eec2f4b2aba731c8e041c2f455395ee05598bd806567b6c
MD5 770a520382aa53e21bcdcf83cf52394d
BLAKE2b-256 cfe365f3fa7b06f25f79291658d895f2cb6bd85448dd158b372b4fe7b150f652

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page