# 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:
```sh
pip install LuhnExtended
```
## Usage
### Importing the Library
```python
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**:
```python
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**:
```python
# 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**:
```python
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**:
```python
full_string = append("35693803564380", 7)
print(f"Appended check digit to ('35693803564380', 7): {full_string}") # Output: '356938035643806'
```
## Author
Developed by Luhn Extended.
Raw data
{
"_id": null,
"home_page": null,
"name": "LuhnExtended",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "luhn, checksum, verification, generation",
"author": "Luhn Extended",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/aa/48/bbad37b5fa3f1c67cd8f428ce61b9fe1cf2dafc3173a7fc223940ae654a9/luhnextended-1.0.1.tar.gz",
"platform": null,
"description": "# LuhnExtended\n\nLuhnExtended 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.\n\n## Features\n- **Checksum Calculation**: Calculate the Luhn checksum for a given string of digits.\n- **Verification**: Verify whether a string of digits satisfies the Luhn algorithm.\n- **Check Digit Generation**: Generate the correct check digit to append to a string of digits.\n- **Append Check Digit**: Easily append the correct Luhn check digit to a string.\n\n## Installation\n\nInstall the `LuhnExtended` library using `pip` directly from PyPI:\n\n```sh\npip install LuhnExtended\n```\n\n## Usage\n\n### Importing the Library\n\n```python\nfrom LuhnExtended import checksum, verify, generate, append\n```\n\n### Functions\n\n#### `checksum(string)`\nCompute the Luhn checksum for the provided string of digits. Note that this assumes the check digit is in place.\n\n**Example**:\n\n```python\nchecksum_value = checksum(\"356938035643806\")\nprint(checksum_value) # Output: 7\n```\n\n#### `verify(string, checksum_expected=0)`\nCheck if the provided string of digits satisfies the Luhn checksum.\n\n**Parameters**:\n- `string` (str): The string of digits to verify.\n- `checksum_expected` (int, optional): Expected checksum value.\n\n**Example**:\n\n```python\n# Test verification\nis_valid = verify(\"356938035643806\", 7)\nprint(f\"Is ('356938035643806', 7) valid? {is_valid}\") # Expected output: True\n\nis_invalid = verify(\"356938035643806\", 0)\nprint(f\"Is ('356938035643806', 0) valid? {is_invalid}\") # Expected output: False\n\nis_invalid = verify(\"534618613411236\", 7)\nprint(f\"Is ('534618613411236', 7) valid? {is_invalid}\") # Expected output: False\n```\n\n#### `generate(string, checksum_desired=0)`\nGenerate the Luhn check digit to append to the provided string.\n\n**Parameters**:\n- `string` (str): The string of digits to generate a check digit for.\n- `checksum_desired` (int, optional): Desired checksum value (default is `0`).\n\n**Example**:\n\n```python\ncheck_digit = generate(\"35693803564380\", 7)\nprint(f\"Generated check digit for ('35693803564380', 7): {check_digit}\") # Output: 6\n```\n\n#### `append(string, checksum_desired=0)`\nAppend the Luhn check digit to the end of the provided string.\n\n**Parameters**:\n- `string` (str): The string of digits to append a check digit to.\n- `checksum_desired` (int, optional): Desired checksum value (default is `0`).\n\n**Example**:\n\n```python\nfull_string = append(\"35693803564380\", 7)\nprint(f\"Appended check digit to ('35693803564380', 7): {full_string}\") # Output: '356938035643806'\n```\n\n## Author\n\nDeveloped by Luhn Extended.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library for advanced Luhn algorithm operations",
"version": "1.0.1",
"project_urls": {
"Repository": "https://github.com/luhnextended/luhnextended"
},
"split_keywords": [
"luhn",
" checksum",
" verification",
" generation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b3bdb6a475206cb51cabeb91e4554dae44a6047b62633859c6ffc428dfe218f8",
"md5": "c7ec3849953145b692b03ba98e3cc633",
"sha256": "9b7bf298762647be1764504edd50f2b9c62dc9f9da1eee8f9d30793bf1d736e0"
},
"downloads": -1,
"filename": "LuhnExtended-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c7ec3849953145b692b03ba98e3cc633",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 3686,
"upload_time": "2024-12-17T02:06:36",
"upload_time_iso_8601": "2024-12-17T02:06:36.569912Z",
"url": "https://files.pythonhosted.org/packages/b3/bd/b6a475206cb51cabeb91e4554dae44a6047b62633859c6ffc428dfe218f8/LuhnExtended-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "aa48bbad37b5fa3f1c67cd8f428ce61b9fe1cf2dafc3173a7fc223940ae654a9",
"md5": "acc2296d5a44d3c0b2142342966c5fa1",
"sha256": "b528d678dbff43d690ce0a090c838c1c49d7d45b1ccf96d17605a8d8c9ea8630"
},
"downloads": -1,
"filename": "luhnextended-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "acc2296d5a44d3c0b2142342966c5fa1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3595,
"upload_time": "2024-12-17T02:06:38",
"upload_time_iso_8601": "2024-12-17T02:06:38.622531Z",
"url": "https://files.pythonhosted.org/packages/aa/48/bbad37b5fa3f1c67cd8f428ce61b9fe1cf2dafc3173a7fc223940ae654a9/luhnextended-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-17 02:06:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "luhnextended",
"github_project": "luhnextended",
"github_not_found": true,
"lcname": "luhnextended"
}