Skip to content

Commit

Permalink
Merge pull request #2 from AsfhtgkDavid/dev
Browse files Browse the repository at this point in the history
1.2.0v done
  • Loading branch information
AsfhtgkDavid authored Jan 7, 2025
2 parents 2d2c8a8 + ba24743 commit 5dbff3a
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 133 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Python tests

on: [push, pull_request]
on: [pull_request]

jobs:
unittests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
python-version: [ "3.10", "3.11", "3.12", "3.13" ]

env:
PYTHONPATH: ${{ github.workspace }}
Expand All @@ -20,14 +20,15 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Run Tests
run: |
pip install -r requirements.txt
cd tests
python -m unittest nalenc.py
mypy-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
python-version: [ "3.10", "3.11", "3.12", "3.13" ]

env:
PYTHONPATH: ${{ github.workspace }}
Expand All @@ -41,4 +42,5 @@ jobs:
- name: Run Tests
run: |
pip install mypy
python -m mypy src/nalenc/*
pip install -r requirements.txt
python -m mypy src/nalenc/*
116 changes: 75 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,62 @@
# 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.
**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
---

## 🚀 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`.
- **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
---

To install the library, use pip:
## 📦 Installation

Install the library via pip:

```bash
pip install nalenc
```

## Usage
---

### Importing the Library
## 📝 Usage

### 🔗 Importing the Library

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

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

Example:

```python
import nalenc
import random

# Generate a password as a list of integers
password = [random.randint(0, 255) for _ in range(512)]
# Generate a password as a NumPy array
password = np.random.randint(0, 256, size=512, dtype=np.uint8)
nal = nalenc.NALEnc(password)
```

### Encrypting Data
### 🔒 Encrypting Data

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

- String
- Byte sequence
- Iterable of integers (each integer must be in the range `0-255`)
- **String**
- **Byte sequence**
- **Iterable of integers** (0-255)
- **NumPy array** (dtype: `np.uint8`)

Example:

Expand All @@ -60,25 +67,32 @@ 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
### 🔓 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
decrypted = nal.decrypt(encrypted) # Returns a list of integers

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

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

### Working with Binary Files
### 📂 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.
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:

Expand All @@ -102,46 +116,64 @@ with open("decrypted.bin", "wb") as f:
f.write(bytes(decrypted_data))
```

## Optimal Message Size
---

## 📈 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.
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
## 📚 API Reference

### Class: `NALEnc`

#### Constructor

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

- **password**: The encryption password. It can be a string, byte sequence, or iterable of integers (each in the range `0-255`).
- **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])`
##### `encrypt(msg: str | bytes | Iterable[int] | np.types.NDArray[np.uint8])`

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`).
- **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])`
##### `decrypt(msg: str | bytes | Iterable[int] | np.types.NDArray[np.uint8])`

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.
- **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
---

## 💡 Example Code

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

# Generate a random password
password = [random.randint(0, 255) for _ in range(512)]
password = np.random.randint(0, 256, size=512, dtype=np.uint8)

# Create an instance of NALEnc
nal = nalenc.NALEnc(password)
Expand All @@ -158,9 +190,11 @@ print("Encrypted:", bytes(encrypted)) # Cast to bytes for readability
print("Decrypted:", bytes(decrypted))
```

## License
---

## 📜 License

This library is licensed under the LGPL License. See the LICENSE file for more information.
This library is licensed under the LGPL License. See the COPYING and COPYING.LESSER files for more information.

---

Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ build-backend = "setuptools.build_meta"

[project]
name = "nalenc"
version = "1.0.1"
version = "1.2.0"
description = "Lightweight symetric encryption"
readme = "README.md"
authors = [{ name = "David Lishchyshen", email = "[email protected]" }]
keywords = ["encryption", "lightweight", "symetric", "secure"]
requires-python = ">=3.9"
requires-python = ">=3.10"
classifiers = [
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
Expand All @@ -20,6 +20,9 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
"Typing :: Typed"
]
dependencies = [
"numpy >= 2.1.0"
]

[project.urls]
Homepage = "https://github.com/AsfhtgkDavid/NAL-Encryption"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
numpy >= 2.1.0
2 changes: 1 addition & 1 deletion src/nalenc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

__all__ = ["NALEnc"]
__author__ = 'David Lishchyshen'
__version__ = '1.0.1'
__version__ = '1.2.0'
__email__ = '[email protected]'
Loading

0 comments on commit 5dbff3a

Please sign in to comment.