nalenc


Namenalenc JSON
Version 1.2.0 PyPI version JSON
download
home_pageNone
SummaryLightweight symetric encryption
upload_time2025-01-07 20:01:34
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords encryption lightweight symetric secure
VCS
bugtrack_url
requirements numpy
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

- **Flexible Input:** Encrypt and decrypt strings, binary data, or NumPy arrays.
- **Password Support:** Accepts passwords as strings, bytes, lists of integers (0-255), or NumPy arrays.
- **Optimized for Performance:** Best suited for messages of size `2046n`, where `n ∈ N`.
- **Powered by NumPy:** Leverages NumPy for efficient operations.

---

## 📦 Installation

Install the library via pip:

```bash
pip install nalenc
```

---

## 📝 Usage

### 🔗 Importing the Library

```python
import nalenc
import numpy as np
```

### 🔑 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 in the range `0-255`)
- A NumPy array of integers (dtype must be `np.uint8`)

Example:

```python
# Generate a password as a NumPy array
password = np.random.randint(0, 256, size=512, dtype=np.uint8)
nal = nalenc.NALEnc(password)
```

### 🔒 Encrypting Data

Use the `encrypt` method to encrypt a message. Supported input types:

- **String**
- **Byte sequence**
- **Iterable of integers** (0-255)
- **NumPy array** (dtype: `np.uint8`)

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)

# Encrypt a NumPy array
array_data = np.array([1, 2, 3, 4, 5], dtype=np.uint8)
encrypted_array = nal.encrypt(array_data)
```

### 🔓 Decrypting Data

Use the `decrypt` method to decrypt an encrypted message.

Example:

```python
# Decrypt the encrypted string
decrypted = nal.decrypt(encrypted)  # Returns a list of integers

# Decrypt binary data
decrypted_binary = nal.decrypt(encrypted_binary)

# Decrypt a NumPy array
decrypted_array = nal.decrypt(encrypted_array)
```

### 📂 Working with Binary Files

NALEnc supports encrypting and decrypting binary files. Read the file as binary data, process it, and save the result. Cast the encrypted data 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, ensure message sizes are `2048n - 2`, where `n` is a positive integer. This helps maximize efficiency during encryption and decryption.

---

## 📚 API Reference

### Class: `NALEnc`

#### Constructor

```python
NALEnc(password: str | bytes | Iterable[int] | np.types.NDArray[np.uint8])
```

- **password**: The encryption password. Acceptable types:
  - String
  - Byte sequence
  - Iterable of integers (0-255)
  - NumPy array (`np.types.NDArray[np.uint8]`)

#### Methods

##### `encrypt(msg: str | bytes | Iterable[int] | np.types.NDArray[np.uint8])`

Encrypts the given message.

- **msg**: The message to encrypt. Input types:
  - String
  - Byte sequence
  - Iterable of integers (0-255)
  - NumPy array (`np.types.NDArray[np.uint8]`)
- **Returns**: The encrypted message as a list of integers.

##### `decrypt(msg: str | bytes | Iterable[int] | np.types.NDArray[np.uint8])`

Decrypts the given encrypted message.

- **msg**: The encrypted message. Input types:
  - String
  - Byte sequence
  - Iterable of integers (0-255)
  - NumPy array (`np.types.NDArray[np.uint8]`)
- **Returns**: The decrypted message as a list of integers.

---

## 💡 Example Code

```python
import nalenc
import numpy as np

# Generate a random password
password = np.random.randint(0, 256, size=512, dtype=np.uint8)

# 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 COPYING and COPYING.LESSER files 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.10",
    "maintainer_email": null,
    "keywords": "encryption, lightweight, symetric, secure",
    "author": null,
    "author_email": "David Lishchyshen <microdaika1@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/3d/10/128d93d876dfa1039bc5027790a99dabb1bd3ae20b6c852b7dfa364ef738/nalenc-1.2.0.tar.gz",
    "platform": null,
    "description": "# NALEnc - Python Encryption Library\n\n**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.\n\n---\n\n## \ud83d\ude80 Features\n\n- **Flexible Input:** Encrypt and decrypt strings, binary data, or NumPy arrays.\n- **Password Support:** Accepts passwords as strings, bytes, lists of integers (0-255), or NumPy arrays.\n- **Optimized for Performance:** Best suited for messages of size `2046n`, where `n \u2208 N`.\n- **Powered by NumPy:** Leverages NumPy for efficient operations.\n\n---\n\n## \ud83d\udce6 Installation\n\nInstall the library via pip:\n\n```bash\npip install nalenc\n```\n\n---\n\n## \ud83d\udcdd Usage\n\n### \ud83d\udd17 Importing the Library\n\n```python\nimport nalenc\nimport numpy as np\n```\n\n### \ud83d\udd11 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 in the range `0-255`)\n- A NumPy array of integers (dtype must be `np.uint8`)\n\nExample:\n\n```python\n# Generate a password as a NumPy array\npassword = np.random.randint(0, 256, size=512, dtype=np.uint8)\nnal = nalenc.NALEnc(password)\n```\n\n### \ud83d\udd12 Encrypting Data\n\nUse the `encrypt` method to encrypt a message. Supported input types:\n\n- **String**\n- **Byte sequence**\n- **Iterable of integers** (0-255)\n- **NumPy array** (dtype: `np.uint8`)\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# Encrypt a NumPy array\narray_data = np.array([1, 2, 3, 4, 5], dtype=np.uint8)\nencrypted_array = nal.encrypt(array_data)\n```\n\n### \ud83d\udd13 Decrypting Data\n\nUse the `decrypt` method to decrypt an encrypted message.\n\nExample:\n\n```python\n# Decrypt the encrypted string\ndecrypted = nal.decrypt(encrypted)  # Returns a list of integers\n\n# Decrypt binary data\ndecrypted_binary = nal.decrypt(encrypted_binary)\n\n# Decrypt a NumPy array\ndecrypted_array = nal.decrypt(encrypted_array)\n```\n\n### \ud83d\udcc2 Working with Binary Files\n\nNALEnc supports encrypting and decrypting binary files. Read the file as binary data, process it, and save the result. Cast the encrypted data 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---\n\n## \ud83d\udcc8 Optimal Message Size\n\nFor best performance, ensure message sizes are `2048n - 2`, where `n` is a positive integer. This helps maximize efficiency during encryption and decryption.\n\n---\n\n## \ud83d\udcda API Reference\n\n### Class: `NALEnc`\n\n#### Constructor\n\n```python\nNALEnc(password: str | bytes | Iterable[int] | np.types.NDArray[np.uint8])\n```\n\n- **password**: The encryption password. Acceptable types:\n  - String\n  - Byte sequence\n  - Iterable of integers (0-255)\n  - NumPy array (`np.types.NDArray[np.uint8]`)\n\n#### Methods\n\n##### `encrypt(msg: str | bytes | Iterable[int] | np.types.NDArray[np.uint8])`\n\nEncrypts the given message.\n\n- **msg**: The message to encrypt. Input types:\n  - String\n  - Byte sequence\n  - Iterable of integers (0-255)\n  - NumPy array (`np.types.NDArray[np.uint8]`)\n- **Returns**: The encrypted message as a list of integers.\n\n##### `decrypt(msg: str | bytes | Iterable[int] | np.types.NDArray[np.uint8])`\n\nDecrypts the given encrypted message.\n\n- **msg**: The encrypted message. Input types:\n  - String\n  - Byte sequence\n  - Iterable of integers (0-255)\n  - NumPy array (`np.types.NDArray[np.uint8]`)\n- **Returns**: The decrypted message as a list of integers.\n\n---\n\n## \ud83d\udca1 Example Code\n\n```python\nimport nalenc\nimport numpy as np\n\n# Generate a random password\npassword = np.random.randint(0, 256, size=512, dtype=np.uint8)\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---\n\n## \ud83d\udcdc License\n\nThis library is licensed under the LGPL License. See the COPYING and COPYING.LESSER files 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.2.0",
    "project_urls": {
        "Homepage": "https://github.com/AsfhtgkDavid/NAL-Encryption"
    },
    "split_keywords": [
        "encryption",
        " lightweight",
        " symetric",
        " secure"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "98a79c95f3b953d464545644fa2ad979d00c98d81c893da63f528c775c2d70e9",
                "md5": "8c7b7716f578a08c34d4d0747904e5b6",
                "sha256": "a2ad5bc7c26b435462dc680d5f77d4c0e6b7b0748837258723d3dc95435d18f3"
            },
            "downloads": -1,
            "filename": "nalenc-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8c7b7716f578a08c34d4d0747904e5b6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 34712,
            "upload_time": "2025-01-07T20:01:31",
            "upload_time_iso_8601": "2025-01-07T20:01:31.802114Z",
            "url": "https://files.pythonhosted.org/packages/98/a7/9c95f3b953d464545644fa2ad979d00c98d81c893da63f528c775c2d70e9/nalenc-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3d10128d93d876dfa1039bc5027790a99dabb1bd3ae20b6c852b7dfa364ef738",
                "md5": "78102acbda4d01f5b0d84ce109f15b04",
                "sha256": "737a758a8bd6faa784435e2858e1801e82b814473a5322797ff19cbc94df1fa8"
            },
            "downloads": -1,
            "filename": "nalenc-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "78102acbda4d01f5b0d84ce109f15b04",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 30498,
            "upload_time": "2025-01-07T20:01:34",
            "upload_time_iso_8601": "2025-01-07T20:01:34.382164Z",
            "url": "https://files.pythonhosted.org/packages/3d/10/128d93d876dfa1039bc5027790a99dabb1bd3ae20b6c852b7dfa364ef738/nalenc-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-07 20:01:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AsfhtgkDavid",
    "github_project": "NAL-Encryption",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "2.1.0"
                ]
            ]
        }
    ],
    "lcname": "nalenc"
}
        
Elapsed time: 0.36336s