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.2.tar.gz (4.8 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: bytekit-3.4.2.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.2.tar.gz
Algorithm Hash digest
SHA256 cae180cd4416303a6a7c1b26891ba382bfab874f1862427777678ef646b44098
MD5 53fd6b2e815f9f889972451af38b529f
BLAKE2b-256 9001625cea673e838ddcdbe3b86e2f9e61768416f4b1e41301200477729ffdd1

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