Skip to main content

Python bindings for Hexahexacontadecimal (base66) encoding

Project description

Python bindings for the k-hhc (Hexahexacontadecimal) C++ library.

This project is intended to be an exploration in creating performant, secure, and portable algorithms, while also being a learning experience for me. Take it with a grain of salt.

Inspired by hexahexacontadecimal by Alexander Ljungberg

Installation

# From the python directory
cd python
pip install .

# Or for development
pip install -e .

Requirements

  • Python 3.7+
  • C++17 compatible compiler (clang++ recommended)
  • pybind11 (build-time only; pulled in automatically by pip/setuptools)

Release build behavior

Release wheels are built with NDEBUG defined. Internal HHC_ASSERT failures do not print a message; they terminate the process via a trap instruction (__builtin_trap). This fail-fast behavior is intentional for release builds.

Usage

Basic Example

import k_hhc

# Encode a 32-bit value
value = 424242
padded = k_hhc.encode_padded_32bit(value)      # Returns: "--.TNv"
unpadded = k_hhc.encode_unpadded_32bit(value)  # Returns: ".TNv"

# Decode a string
decoded = k_hhc.decode_32bit(".TNv")  # Returns: 424242

# 64-bit operations
big_value = 9876543210
padded64 = k_hhc.encode_padded_64bit(big_value)      # Returns: "-----5tVfK4"
unpadded64 = k_hhc.encode_unpadded_64bit(big_value)  # Returns: "5tVfK4"
decoded64 = k_hhc.decode_64bit("5tVfK4")  # Returns: 9876543210

Error Handling

import k_hhc

try:
    # Invalid characters
    k_hhc.decode_32bit("INVALID!")
except ValueError as e:
    print(f"Invalid string: {e}")

try:
    # Value exceeds bounds
    k_hhc.decode_32bit("1QLCp2")  # Exceeds UINT32_MAX
except OverflowError as e:
    print(f"Value too large: {e}")

API Reference

Functions

  • encode_padded_32bit(value: int) -> str: Encode a 32-bit integer to a padded 6-character string
  • encode_unpadded_32bit(value: int) -> str: Encode a 32-bit integer to an unpadded string
  • decode_32bit(encoded: str) -> int: Decode a string to a 32-bit integer
  • encode_padded_64bit(value: int) -> str: Encode a 64-bit integer to a padded 11-character string
  • encode_unpadded_64bit(value: int) -> str: Encode a 64-bit integer to an unpadded string
  • decode_64bit(encoded: str) -> int: Decode a string to a 64-bit integer

Constants

  • HHC_32BIT_ENCODED_LENGTH: Length of padded 32-bit encoded strings (6)
  • HHC_64BIT_ENCODED_LENGTH: Length of padded 64-bit encoded strings (11)
  • HHC_32BIT_STRING_LENGTH: Buffer size for 32-bit encode output (8)
  • HHC_64BIT_STRING_LENGTH: Buffer size for 64-bit encode output (16)
  • HHC_32BIT_ENCODED_MAX_STRING: Maximum valid padded 32-bit encoded string ("1QLCp1")
  • HHC_64BIT_ENCODED_MAX_STRING: Maximum valid padded 64-bit encoded string ("9lH9ebONzYD")
  • ALPHABET: The HHC alphabet string (66 characters)

Exceptions

  • ValueError: Raised when decoding a string with invalid characters
  • OverflowError: Raised when decoding a string that exceeds the bit bounds

Examples

See the examples/ directory for complete examples:

  • encode_example.py: Demonstrates encoding functionality
  • decode_example.py: Demonstrates decoding with error handling and round-trip tests

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

k_hhc-1.1.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

k_hhc-1.1.0-cp37-abi3-win_amd64.whl (17.7 kB view details)

Uploaded CPython 3.7+Windows x86-64

k_hhc-1.1.0-cp37-abi3-musllinux_1_2_x86_64.whl (881.7 kB view details)

Uploaded CPython 3.7+musllinux: musl 1.2+ x86-64

k_hhc-1.1.0-cp37-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (16.5 kB view details)

Uploaded CPython 3.7+manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

k_hhc-1.1.0-cp37-abi3-macosx_10_9_universal2.whl (20.0 kB view details)

Uploaded CPython 3.7+macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file k_hhc-1.1.0.tar.gz.

File metadata

  • Download URL: k_hhc-1.1.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for k_hhc-1.1.0.tar.gz
Algorithm Hash digest
SHA256 00fe39401fc6a687af2a6b23f22b84eb1384dcbdc6a35891f89251be28b844fc
MD5 c41bc6e70e6bce5eba8f9cb18ac0fbcd
BLAKE2b-256 4217f3a23b80a0e217d268a127ab7f4a6eb66f88201d96053ee08d0ab039e71c

See more details on using hashes here.

Provenance

The following attestation bundles were made for k_hhc-1.1.0.tar.gz:

Publisher: release.yml on kirbyevanj/k-hhc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file k_hhc-1.1.0-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: k_hhc-1.1.0-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: CPython 3.7+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for k_hhc-1.1.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3b306f8019b5ba988f6940e8853eccfc3b1a6ffa8f7ac7d3bc31355229715906
MD5 78e7c9613cbcfaf5e862dd1799ce41ca
BLAKE2b-256 44b2441216d8889725c3719b06ca5be5f166c0fe47a14bf91e8551123a0bddd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for k_hhc-1.1.0-cp37-abi3-win_amd64.whl:

Publisher: release.yml on kirbyevanj/k-hhc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file k_hhc-1.1.0-cp37-abi3-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: k_hhc-1.1.0-cp37-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 881.7 kB
  • Tags: CPython 3.7+, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for k_hhc-1.1.0-cp37-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 26eaa4f831bacfbda9c14a36de58ae4d4ee6591f2f2e73eab0f3587bd5bfb988
MD5 24f9145f08fcc4f975f1ba84f69e5aff
BLAKE2b-256 effee2a570012dd29a7051f32936c9bbc66282379336931c14a327102329a7ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for k_hhc-1.1.0-cp37-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on kirbyevanj/k-hhc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file k_hhc-1.1.0-cp37-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for k_hhc-1.1.0-cp37-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9ba6a14564f2b998f1b445c3859c8414e1b146068659e12bb4becc48be635a7c
MD5 5ef990889ef9ae85f721045e98865418
BLAKE2b-256 82b6dfa7203a951ac7976dcede15c08e00859af6fccff7c4584c6b3fba4d35ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for k_hhc-1.1.0-cp37-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on kirbyevanj/k-hhc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file k_hhc-1.1.0-cp37-abi3-macosx_10_9_universal2.whl.

File metadata

  • Download URL: k_hhc-1.1.0-cp37-abi3-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: CPython 3.7+, macOS 10.9+ universal2 (ARM64, x86-64)
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for k_hhc-1.1.0-cp37-abi3-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 9e022858d0923b7d80f3d28871f793e3545a913b578ce37afc124672e9cbe42d
MD5 832f886070e9e90c0c7bbf1099598214
BLAKE2b-256 d40739d9799db0473cb7d2e3cbff8fc1598f68b12534ec0dddd885f699c5a8a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for k_hhc-1.1.0-cp37-abi3-macosx_10_9_universal2.whl:

Publisher: release.yml on kirbyevanj/k-hhc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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