# NALEnc - Python Encryption Library
NALEnc is a lightweight Python encryption library designed for securely encrypting and decrypting text and binary data. With an intuitive interface and robust functionality, it is ideal for developers seeking a straightforward yet effective encryption solution.
## Features
- Encrypt and decrypt strings or binary data.
- Supports passwords as strings, bytes, or lists of integers (0-255).
- Optimized for messages of size `2046n`, where `n ∈ N`.
## Installation
To install the library, use pip:
```bash
pip install nalenc
```
## Usage
### Importing the Library
```python
import nalenc
```
### Creating an Instance of NALEnc
To use the library, create an instance of the `NALEnc` class with a password. The password can be:
- A string
- A byte sequence
- An iterable of integers (each integer must be in the range `0-255`)
Example:
```python
import nalenc
import random
# Generate a password as a list of integers
password = [random.randint(0, 255) for _ in range(512)]
nal = nalenc.NALEnc(password)
```
### Encrypting Data
Use the `encrypt` method to encrypt a message. The message can be a:
- String
- Byte sequence
- Iterable of integers (each integer must be in the range `0-255`)
Example:
```python
# Encrypt a string
encrypted = nal.encrypt("Hello, World!")
# Encrypt binary data
binary_data = b"\x89PNG\r\n\x1a\n"
encrypted_binary = nal.encrypt(binary_data)
```
### Decrypting Data
Use the `decrypt` method to decrypt an encrypted message.
Example:
```python
# Decrypt the encrypted string
original = nal.decrypt(encrypted) # Returns a list of integers
# Decrypt binary data
original_binary = nal.decrypt(encrypted_binary)
```
### Working with Binary Files
NALEnc supports encrypting and decrypting binary files. Simply read the file as binary data, encrypt or decrypt it, and then save the result. Note that the encrypted data needs to be cast to `bytes` before writing to a file.
Example:
```python
# Encrypt a binary file
with open("input.bin", "rb") as f:
data = f.read()
encrypted_data = nal.encrypt(data)
with open("output.enc", "wb") as f:
f.write(bytes(encrypted_data))
# Decrypt the binary file
with open("output.enc", "rb") as f:
encrypted_data = f.read()
decrypted_data = nal.decrypt(encrypted_data)
with open("decrypted.bin", "wb") as f:
f.write(bytes(decrypted_data))
```
## Optimal Message Size
For best performance, messages should have sizes of `2046n`, where `n` is a positive integer. This helps to maximize efficiency and ensure optimal encryption.
## API Reference
### Class: `NALEnc`
#### Constructor
```python
NALEnc(password: str | bytes | Iterable[int])
```
- **password**: The encryption password. It can be a string, byte sequence, or iterable of integers (each in the range `0-255`).
#### Methods
##### `encrypt(msg: str | bytes | Iterable[int])`
Encrypts the given message.
- **msg**: The message to encrypt. Can be a string, byte sequence, or iterable of integers (each in the range `0-255`).
- **Returns**: The encrypted message as a list of integers.
##### `decrypt(msg: str | bytes | Iterable[int])`
Decrypts the given encrypted message.
- **msg**: The encrypted message. Can be a string, byte sequence, or iterable of integers (each in the range `0-255`).
- **Returns**: The original message as a list of integers.
## Example Code
```python
import nalenc
import random
# Generate a random password
password = [random.randint(0, 255) for _ in range(512)]
# Create an instance of NALEnc
nal = nalenc.NALEnc(password)
# Encrypt a message
message = "Encrypt this message!"
encrypted = nal.encrypt(message)
# Decrypt the message
decrypted = nal.decrypt(encrypted)
print("Original:", message)
print("Encrypted:", bytes(encrypted)) # Cast to bytes for readability
print("Decrypted:", bytes(decrypted))
```
## License
This library is licensed under the LGPL License. See the LICENSE file for more information.
---
For questions, feedback, or contributions, feel free to open an issue on the [GitHub repository](https://github.com/AsfhtgkDavid/NAL-Encryption).
Raw data
{
"_id": null,
"home_page": null,
"name": "nalenc",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "encryption, lightweight, symetric, secure",
"author": null,
"author_email": "David Lishchyshen <microdaika1@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/56/cb/8903cb1100409f0a23271d833da1f32ef7961b44849833999e5ed731dabc/nalenc-1.0.1.tar.gz",
"platform": null,
"description": "# NALEnc - Python Encryption Library\n\nNALEnc is a lightweight Python encryption library designed for securely encrypting and decrypting text and binary data. With an intuitive interface and robust functionality, it is ideal for developers seeking a straightforward yet effective encryption solution.\n\n## Features\n\n- Encrypt and decrypt strings or binary data.\n- Supports passwords as strings, bytes, or lists of integers (0-255).\n- Optimized for messages of size `2046n`, where `n \u2208 N`.\n\n## Installation\n\nTo install the library, use pip:\n\n```bash\npip install nalenc\n```\n\n## Usage\n\n### Importing the Library\n\n```python\nimport nalenc\n```\n\n### Creating an Instance of NALEnc\n\nTo use the library, create an instance of the `NALEnc` class with a password. The password can be:\n\n- A string\n- A byte sequence\n- An iterable of integers (each integer must be in the range `0-255`)\n\nExample:\n\n```python\nimport nalenc\nimport random\n\n# Generate a password as a list of integers\npassword = [random.randint(0, 255) for _ in range(512)]\nnal = nalenc.NALEnc(password)\n```\n\n### Encrypting Data\n\nUse the `encrypt` method to encrypt a message. The message can be a:\n\n- String\n- Byte sequence\n- Iterable of integers (each integer must be in the range `0-255`)\n\nExample:\n\n```python\n# Encrypt a string\nencrypted = nal.encrypt(\"Hello, World!\")\n\n# Encrypt binary data\nbinary_data = b\"\\x89PNG\\r\\n\\x1a\\n\"\nencrypted_binary = nal.encrypt(binary_data)\n```\n\n### Decrypting Data\n\nUse the `decrypt` method to decrypt an encrypted message.\n\nExample:\n\n```python\n# Decrypt the encrypted string\noriginal = nal.decrypt(encrypted) # Returns a list of integers\n\n# Decrypt binary data\noriginal_binary = nal.decrypt(encrypted_binary)\n```\n\n### Working with Binary Files\n\nNALEnc supports encrypting and decrypting binary files. Simply read the file as binary data, encrypt or decrypt it, and then save the result. Note that the encrypted data needs to be cast to `bytes` before writing to a file.\n\nExample:\n\n```python\n# Encrypt a binary file\nwith open(\"input.bin\", \"rb\") as f:\n data = f.read()\n\nencrypted_data = nal.encrypt(data)\n\nwith open(\"output.enc\", \"wb\") as f:\n f.write(bytes(encrypted_data))\n\n# Decrypt the binary file\nwith open(\"output.enc\", \"rb\") as f:\n encrypted_data = f.read()\n\ndecrypted_data = nal.decrypt(encrypted_data)\n\nwith open(\"decrypted.bin\", \"wb\") as f:\n f.write(bytes(decrypted_data))\n```\n\n## Optimal Message Size\n\nFor best performance, messages should have sizes of `2046n`, where `n` is a positive integer. This helps to maximize efficiency and ensure optimal encryption.\n\n## API Reference\n\n### Class: `NALEnc`\n\n#### Constructor\n\n```python\nNALEnc(password: str | bytes | Iterable[int])\n```\n\n- **password**: The encryption password. It can be a string, byte sequence, or iterable of integers (each in the range `0-255`).\n\n#### Methods\n\n##### `encrypt(msg: str | bytes | Iterable[int])`\n\nEncrypts the given message.\n\n- **msg**: The message to encrypt. Can be a string, byte sequence, or iterable of integers (each in the range `0-255`).\n- **Returns**: The encrypted message as a list of integers.\n\n##### `decrypt(msg: str | bytes | Iterable[int])`\n\nDecrypts the given encrypted message.\n\n- **msg**: The encrypted message. Can be a string, byte sequence, or iterable of integers (each in the range `0-255`).\n- **Returns**: The original message as a list of integers.\n\n## Example Code\n\n```python\nimport nalenc\nimport random\n\n# Generate a random password\npassword = [random.randint(0, 255) for _ in range(512)]\n\n# Create an instance of NALEnc\nnal = nalenc.NALEnc(password)\n\n# Encrypt a message\nmessage = \"Encrypt this message!\"\nencrypted = nal.encrypt(message)\n\n# Decrypt the message\ndecrypted = nal.decrypt(encrypted)\n\nprint(\"Original:\", message)\nprint(\"Encrypted:\", bytes(encrypted)) # Cast to bytes for readability\nprint(\"Decrypted:\", bytes(decrypted))\n```\n\n## License\n\nThis library is licensed under the LGPL License. See the LICENSE file for more information.\n\n---\n\nFor questions, feedback, or contributions, feel free to open an issue on the [GitHub repository](https://github.com/AsfhtgkDavid/NAL-Encryption).\n",
"bugtrack_url": null,
"license": null,
"summary": "Lightweight symetric encryption",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/AsfhtgkDavid/NAL-Encryption"
},
"split_keywords": [
"encryption",
" lightweight",
" symetric",
" secure"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "46e7ef57a4f0e589e306345c538eaf118af825c2b9b0b3927ff1eb18592b59dc",
"md5": "788e2e100deaa95e7b322485d3757837",
"sha256": "bdbafc07ebb4dc7fa9c967ceeb7a9e1ba41f1fab752ed651e767c1bf645aaddf"
},
"downloads": -1,
"filename": "nalenc-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "788e2e100deaa95e7b322485d3757837",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 34441,
"upload_time": "2025-01-02T14:08:50",
"upload_time_iso_8601": "2025-01-02T14:08:50.813265Z",
"url": "https://files.pythonhosted.org/packages/46/e7/ef57a4f0e589e306345c538eaf118af825c2b9b0b3927ff1eb18592b59dc/nalenc-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "56cb8903cb1100409f0a23271d833da1f32ef7961b44849833999e5ed731dabc",
"md5": "681d63d166c0c89a188f5653a48162d8",
"sha256": "462a3c18d67fcbe5ae1a4ef3bbd2625a54cd5998c769b0aecaa96ad2bebfce36"
},
"downloads": -1,
"filename": "nalenc-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "681d63d166c0c89a188f5653a48162d8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 29910,
"upload_time": "2025-01-02T14:08:52",
"upload_time_iso_8601": "2025-01-02T14:08:52.501098Z",
"url": "https://files.pythonhosted.org/packages/56/cb/8903cb1100409f0a23271d833da1f32ef7961b44849833999e5ed731dabc/nalenc-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-02 14:08:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "AsfhtgkDavid",
"github_project": "NAL-Encryption",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "nalenc"
}