Python API¶
Quick example¶
from bitsplit import encode, decode
# Encode any bytes
data = open("photo.jpg", "rb").read()
block, key = encode(data)
# block is bytes (the binary block)
# key is a string like "340079...:8843264:1105424"
# Decode back
restored = decode(block, key)
assert restored == data
Functions¶
Core encode/decode logic.
- bitsplit.core.encode(data)[source]¶
Encode bytes into a binary block and a key string.
- Parameters:
data (bytes) – Source file content as bytes.
- Returns:
count:size” string.
- Return type:
(block, key) where block is bytes and key is “data
- bitsplit.core.decode(block, key)[source]¶
Decode a binary block using the key string.
- Parameters:
block (bytes) – Binary block (indices).
key (str) – Key string in “data:count:size” format (masked with block hash).
- Returns:
Restored file content as bytes.
- Return type:
bytes
Key string format¶
The key returned by encode() is a colon-separated string:
<data>:<count>:<size>
Field |
Type |
Description |
|---|---|---|
|
|
Top 128 bits of the file as a number |
|
|
Number of lower bits stored in the block |
|
|
Original file size in bytes |
Constants¶
- bitsplit.core.KEY_BITS = 128¶
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4
KEY_BITS = 128 — the number of bits sliced off as the key. This matches AES-128 key space (2^128 variants).