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)
Metadata
Release files for crypt-tool 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| crypt_tool-0.1.3.tar.gz | 3.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| crypt_tool-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.8 kB
Release files / crypt_tool-0.1.3.tar.gz
| Download URL | crypt_tool-0.1.3.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0c91637ad8a7d5dd4ece82e6bd383e9bfc7313475597dd080011c6212cb6c80d
|
|
BLAKE2b-256 checksum How to use checksums |
59a3875b4681ac5cc717fbe47859816b2d2ee02ad480e7c8b1265646c7b0477c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / crypt_tool-0.1.3-py3-none-any.whl
| Download URL | crypt_tool-0.1.3-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
58c57cb599eff8a2b1cd645a845d9f8463be9848ac46e26085e10e3e19607ff6
|
|
BLAKE2b-256 checksum How to use checksums |
6b366e408cdabfa6c212d53273167fe21b81bf902e8c605cfdec0c46b434878a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|