A pure python implementation of DES
Project description
DES-Python
Data Encryption Standard (DES) implemented in pure Python
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:
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.
import des_PurePy
des = des_PurePy.DES("0x133457799bbcdff1")
You can encrypt by calling encrypt() and passing in a hex string or bytes object.
des.encrypt("0x0123456789abcdef") # -> "0x85e813540f0ab405fdf2e174492922f8"
You can simarly decrypt by calling decrypt() and passing in a hex string or bytes object.
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.
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file des_purepy-1.0.8.tar.gz.
File metadata
- Download URL: des_purepy-1.0.8.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e466651d0737cf3d38a0575fb7912d8bf39990ff0e23f52f8caa2bbb53136c1
|
|
| MD5 |
aae1388e25abf0f5934e632c284527fe
|
|
| BLAKE2b-256 |
8c7e6b01b17642dfddcc4c85daf5156dddab7b95643ce798f915301ecfd963a3
|
File details
Details for the file des_purepy-1.0.8-py3-none-any.whl.
File metadata
- Download URL: des_purepy-1.0.8-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da4a2456a9d3bd115913eb010ac71f029cd301e862f64a2fe0b62c0df50f0263
|
|
| MD5 |
7deeac0f957aabe12a2f90e31b056fa1
|
|
| BLAKE2b-256 |
74a30dbc69bdbf644ca2e9a65dd004b0feefd21222e9bde4589c04c00183735d
|