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

Method 1: Using CMake (recommended for development)

# Clone the repository
git clone https://github.com/kirbyevanj/k-hhc.git
cd k-hhc

# From the root directory
mkdir build && cd build
cmake .. -DHHC_BUILD_PYTHON=ON
make

# The Python module will be in build/python/

Method 2: Using setuptools

# From the python directory
cd python
pip install .

# Or for development
pip install -e .

Requirements

  • Python 3.6+
  • pybind11
  • C++23 compatible compiler (clang++ recommended)

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)
  • ALPHABET: The HHC alphabet string

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.0.8.tar.gz (16.9 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.0.8-cp37-abi3-win_amd64.whl (18.2 kB view details)

Uploaded CPython 3.7+Windows x86-64

k_hhc-1.0.8-cp37-abi3-musllinux_1_1_x86_64.whl (562.7 kB view details)

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

k_hhc-1.0.8-cp37-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (18.3 kB view details)

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

k_hhc-1.0.8-cp37-abi3-macosx_10_9_universal2.whl (21.1 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for k_hhc-1.0.8.tar.gz
Algorithm Hash digest
SHA256 19a268cb672a9f8551f2bf39715eb16ffa065e7528222a64f4f52467781d49f8
MD5 8b3a309861c9d50ff8c44adf34cd98f9
BLAKE2b-256 377e5c11d294e37d6de2d638e563507b9758cc6ea6d414fc0399e6d086b5df5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for k_hhc-1.0.8.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.0.8-cp37-abi3-win_amd64.whl.

File metadata

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

File hashes

Hashes for k_hhc-1.0.8-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8603d6c8ca676ec124f2378fdd5f99f835f2b2ed13d5e8056b862336d791077e
MD5 32d7c5a8b240d9401b06223abbd53c60
BLAKE2b-256 0b5eab6b2fc17b70ac4678ea4600b96e251cd82fab2a88826368de869c3d1016

See more details on using hashes here.

Provenance

The following attestation bundles were made for k_hhc-1.0.8-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.0.8-cp37-abi3-musllinux_1_1_x86_64.whl.

File metadata

  • Download URL: k_hhc-1.0.8-cp37-abi3-musllinux_1_1_x86_64.whl
  • Upload date:
  • Size: 562.7 kB
  • Tags: CPython 3.7+, musllinux: musl 1.1+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for k_hhc-1.0.8-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f3c3894b2cfd5085e75cf9e44b3ef22a519d72e6db872cbedfce588603a199de
MD5 f7c5b35b6e811106c38a3427be2be452
BLAKE2b-256 c25798031f76226712888b2a1e818ed031ea68055dfd885ed25607d570e16809

See more details on using hashes here.

Provenance

The following attestation bundles were made for k_hhc-1.0.8-cp37-abi3-musllinux_1_1_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.0.8-cp37-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for k_hhc-1.0.8-cp37-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 58a76fb705ecd5cf872e21ca2e7793c04fc81c4745b25903abe233384b93c456
MD5 dd4151e9dbbed3cff19744516b6bcd89
BLAKE2b-256 9afc4e69a02563b2e4c4e56d1ce9169f6fa2f639b0e4e3748ed083e62fef0062

See more details on using hashes here.

Provenance

The following attestation bundles were made for k_hhc-1.0.8-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.0.8-cp37-abi3-macosx_10_9_universal2.whl.

File metadata

  • Download URL: k_hhc-1.0.8-cp37-abi3-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 21.1 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.7

File hashes

Hashes for k_hhc-1.0.8-cp37-abi3-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 1e5d55d3c247fea152775845ff488e78afe52e211154eb5cacd68b795c72626e
MD5 47ddd09c943ed9e97cc121342f4a0726
BLAKE2b-256 bbcb8e10ce9119c2cdcd1537d76dc9a842082f86f84eaf46c50d22e964726fa9

See more details on using hashes here.

Provenance

The following attestation bundles were made for k_hhc-1.0.8-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