Metadata-Version: 2.4
Name: des_PurePy
Version: 1.0.9
Summary: A pure python implementation of DES
Project-URL: Homepage, https://github.com/Perez-Herrera-Luna/DES-Python
Author: Luna Perez-Herrera
License-Expression: AGPL-3.0-only
License-File: LICENSE
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# DES-Python

![made-with-python](https://img.shields.io/badge/Made%20with-Python%203-1f425f.svg)
[![license: AGPL-3.0](https://img.shields.io/github/license/Perez-Herrera-Luna/DES-Python.svg)](https://github.com/Perez-Herrera-Luna/DES-Python/blob/main/LICENSE)
[![DES-Python](https://github.com/Perez-Herrera-Luna/DES-Python/actions/workflows/python-app.yml/badge.svg)](https://github.com/Perez-Herrera-Luna/DES-Python/actions/workflows/python-app.yml)

Data Encryption Standard (DES) implemented in pure Python

![Demo](https://github.com/user-attachments/assets/aaa905df-d924-4d52-80f4-b06390c1b523)

## Features

- **Encryption and Decryption**
- **PKCS5 Padding**
- **ECB Mode of Operation**
- **Hex String and Bytes Object Support**

## Installation

Install using your Python package manager of choice:
```bash
pip install des_PurePy
```

## Usage
### Encrypting Hex Strings
Define a `DES` object while passing in your key. The key can be a hex string or a bytes object.
```python
import des_PurePy
des = des_PurePy.DES("0x133457799bbcdff1")
```
You can encrypt by calling `encrypt()` and passing in a hex string or bytes object.
```python
des.encrypt("0x0123456789abcdef")    # -> "0x85e813540f0ab405fdf2e174492922f8"
```
You can simarly decrypt by calling `decrypt()` and passing in a hex string or bytes object.
```python
des.decrypt("0x85e813540f0ab405fdf2e174492922f8")    # -> "0x0123456789abcdef"
```
By default, encryption input is padded to a multiple of the block size (8 bytes) according to PKCS5. Inputs that are multiple blocks long are encrypted using the Electronic Code Book (ECB) mode of operation.
### Encrypting Bytes Objects and Text
Inputs can be hex strings or bytes objects. The key must always be 8 bytes but the encryption input can have any size. 
Because of the bytes object support, with some work, you can encrypt and decrypt text.
```python
import des_PurePy

key = b"password"
des = des_PurePy.DES(key)

ciphertext = des.encrypt(b"secret message")                 # -> "0x0d417ca7d23582bab5e2c9277f801591"
cleartext = des.decrypt(ciphertext)                         # -> "0x736563726574206d657373616765"
cleartext = bytes.fromhex(cleartext[2:]).decode("utf-8")    # -> "secret message"
```
Note that all input is validated so if you passing in an inapropriate input the module will raise a corresponding error.