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+
  • pybind11
  • C++17 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.9.tar.gz (16.1 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.9-cp37-abi3-win_amd64.whl (18.1 kB view details)

Uploaded CPython 3.7+Windows x86-64

k_hhc-1.0.9-cp37-abi3-musllinux_1_1_x86_64.whl (561.7 kB view details)

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

k_hhc-1.0.9-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.0.9-cp37-abi3-macosx_10_9_universal2.whl (20.3 kB view details)

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

File details

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

File metadata

  • Download URL: k_hhc-1.0.9.tar.gz
  • Upload date:
  • Size: 16.1 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.9.tar.gz
Algorithm Hash digest
SHA256 0947ce316d9d785136593fb25bd352c97974d33cae6ae7c5fec35f76261a5396
MD5 a609154b958e3cf5a004d6558f2cc0e9
BLAKE2b-256 51891de53a058dd986a7fbe9c4651ad209d9b6da45b96b6b409b2cd04028abba

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: k_hhc-1.0.9-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 18.1 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.9-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 12856a8d6610981150adb0dca2ee471a2aabbded66c142abafa08b67a9608069
MD5 00bf386e06565950492fa77046dbb8ff
BLAKE2b-256 cdaa65053436f4615f80b6d72d4eb493cdd3bbcefb58269ff5363bc6e87abc23

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: k_hhc-1.0.9-cp37-abi3-musllinux_1_1_x86_64.whl
  • Upload date:
  • Size: 561.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.9-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 16595d3fc7288762632de1289daf615e24081dc448218834403bff2befc281ea
MD5 f54afba460cd56c894fc9ec88670e3d4
BLAKE2b-256 65ce0d5d5c53a678bf79832ae7f1521a76a840926c6fb1a501d7df10593204f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for k_hhc-1.0.9-cp37-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 efd025fb7f5059fa1571754c22cfc1798d981903438a415a2dfd461b99cfe99a
MD5 c1b6933b9463d284ec29bae4b955c4db
BLAKE2b-256 9691f42f16062e56a390978cf4c77e06ff66c6fcabf7f7dc29452a34ca55df20

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: k_hhc-1.0.9-cp37-abi3-macosx_10_9_universal2.whl
  • Upload date:
  • Size: 20.3 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.9-cp37-abi3-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 45d96fab9d5c80ebe8641746f5a8e4b6a33381bd62cc18b05ed96c9d0ca97fb0
MD5 18b47e84053cd5ab25eebf62529b0006
BLAKE2b-256 670ee8120881a3ec3b7d4e4dd8ed008125ecbe4556392bc2f1c82eeb9687934d

See more details on using hashes here.

Provenance

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