Skip to main content

High-performance buffer transformation, encoding, and binary codec primitives

This project has been quarantined.

PyPI Admins need to review this project before it can be restored. While in quarantine, the project is not installable by clients, and cannot be being modified by its maintainers.

Read more in the project in quarantine help article.

Project description

bytekit

High-performance buffer transformation, encoding, and binary codec primitives for Python.

Installation

pip install bytekit

Usage

import bytekit

# XOR encoding
encoded = bytekit.xor(b'hello world', b'key')
decoded = bytekit.xor(encoded, b'key')

# Hex / Base64
hex_str = bytekit.to_hex(b'\xde\xad\xbe\xef')
raw = bytekit.from_hex('deadbeef')
b64 = bytekit.to_base64(b'binary data')

# PKCS7 padding
padded = bytekit.pad_pkcs7(b'short', block_size=16)
original = bytekit.unpad_pkcs7(padded)

# Hashing
digest = bytekit.sha256(b'message')
mac = bytekit.hmac_sha256(b'secret', b'data')

# Binary packing
packed = bytekit.write_uint32_le(0xDEADBEEF)
value = bytekit.read_uint32_le(packed)

# Utilities
chunks = bytekit.split(b'abcdefgh', 3)
rand = bytekit.random_bytes(32)
eq = bytekit.compare(a, b)  # constant-time

API Reference

Encoding

  • xor(data, key) — XOR each byte with cycling key
  • to_hex(buf) / from_hex(str) — hex encode/decode
  • to_base64(buf) / from_base64(str) — base64
  • to_base32(buf) / from_base32(str) — base32

Padding

  • pad(buf, n, byte=0) — right-pad to length n
  • pad_pkcs7(buf, block_size=16) / unpad_pkcs7(buf)

Hashing

  • sha256(buf) / sha256_hex(buf) / md5(buf)
  • hmac_sha256(key, data)
  • crc32(buf)

Binary

  • pack(fmt, *values) / unpack(fmt, buf)
  • read_uint32_le/be(buf, offset) / write_uint32_le/be(value)
  • read_uint16_le/be(buf, offset)

Manipulation

  • concat(*parts) / split(buf, n) / chunks(buf, size)
  • rotate_left(buf, k) / rotate_right(buf, k)
  • reverse(buf) / repeat(buf, n)
  • interleave(a, b) / deinterleave(buf, count)
  • mask(data, mask_byte) / fill(size, byte)

Comparison

  • compare(a, b) — constant-time equality
  • bit_count(buf) — popcount
  • hamming_distance(a, b)

License

MIT

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

bytekit-3.4.1.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file bytekit-3.4.1.tar.gz.

File metadata

  • Download URL: bytekit-3.4.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for bytekit-3.4.1.tar.gz
Algorithm Hash digest
SHA256 289665f50ae7d9beb86c83579b04d26a14b3027d5f4cb6f1a3179824e568d402
MD5 c11030e4eb829c676683063717a34625
BLAKE2b-256 d33d8930c8e4f8eeab3760e4559da0095af11335b380b0a0a21fc1d3d2b79c96

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page