A versatile and efficient cryptography library implemented in Python
Project description
Crypt Tool
crypt_tool 提供了一个简单的加密和数据转换工具集,包含以下组件:
LinearCongruentialGenerator: 生成伪随机数,用于加密和字符串生成。XorCipher: 基于 XOR 的简单加密解密类。BytesBitsConverter: 将字节转换为位、位转换为字节的工具类。
使用示例
# (cd ./python)
# 运行示例函数
python examples/example.py
# 批量测试
python tests/tests.py --verbose
1. 生成随机数
from crypt_tool import system_random, LCG
rand = system_random()
print("A random number:", rand)
seed = b"a seed"
rnd = LCG.from_seed(seed)
print("Random number from seed:", rnd.generate_u8())
print("Random string:", rnd.generate_random_string(20))
2. 加密
from crypt_tool import XorCipher
cipher = XorCipher(b"password1")
data = bytes([0, 255, 128, 64, 32, 16, 8, 4, 2, 1])
encoded = cipher.encode(data)
decoded = cipher.decode(encoded)
assert data == decoded, "Decoded data does not match original"
print("Encoding and decoding successful.")
3. 二进制类型 和 Bytes 类型互相转化
from crypt_tool import BytesBitsConverter
converter = BytesBitsConverter()
bytes_data = bytes([0, 1, 2, 255])
bits = [
0, 0, 0, 0, 0, 0, 0, 0, # 0
0, 0, 0, 0, 0, 0, 0, 1, # 1
0, 0, 0, 0, 0, 0, 1, 0, # 2
1, 1, 1, 1, 1, 1, 1, 1, # 255
]
assert converter.bytes_to_bits(bytes_data) == bits
assert bytes_data == converter.bits_to_bytes(bits)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
crypt_tool-0.1.3.tar.gz
(3.8 kB
view details)
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 crypt_tool-0.1.3.tar.gz.
File metadata
- Download URL: crypt_tool-0.1.3.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c91637ad8a7d5dd4ece82e6bd383e9bfc7313475597dd080011c6212cb6c80d
|
|
| MD5 |
689916a946c0b8bbcc1bb2eb27c6bad8
|
|
| BLAKE2b-256 |
59a3875b4681ac5cc717fbe47859816b2d2ee02ad480e7c8b1265646c7b0477c
|
File details
Details for the file crypt_tool-0.1.3-py3-none-any.whl.
File metadata
- Download URL: crypt_tool-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58c57cb599eff8a2b1cd645a845d9f8463be9848ac46e26085e10e3e19607ff6
|
|
| MD5 |
3455ae280fd88758fdd7d35e7e82ff27
|
|
| BLAKE2b-256 |
6b366e408cdabfa6c212d53273167fe21b81bf902e8c605cfdec0c46b434878a
|