Skip to main content

A Python implementation of the Rune-512 encoding and decoding algorithm.

Project description

Rune-512: Compact Binary Encoding

PyPI version License: MIT

Rune-512 is a binary-to-text encoding scheme designed to safely and compactly embed arbitrary binary data in environments with strict character limits but also support a wide range of Unicode characters, such as social media bios (like Bluesky, Twitter).

It uses a carefully selected 512-character symbolic unicode alphabet that is not visually distracting and can represent data more densely than traditional encodings like Base64, packing 9 bits of data into a single character.

For example, here's 32 random bytes:

⣣⡳⣜▣╎⡇◡━┉◳⠢╖⠿⣺⢔▶⢎⡝╺⡂╍╞▨╿□⣼⣆⢼▤⡖⢀

Here's the string "the fox jumped over the lazy dog":

⣟▴⣨□┩⠆⣍◞⠐⡪⣪▵▃⡖⢄⠛▻⡥⣤⢁▣⢆⢤⠛⠰╺⣲⢁┣⣶⣠

Features

  • Compact: Encodes 9 bits per character, offering significant space savings over Base64.
  • Reliable: Uses a 17-bit checksum derived from the SHA-256 hash of the payload to detect data corruption.
  • Safe: The alphabet consists of Unicode codepoints with wide compatibility across common platforms.
  • Easy to Use: Provides a simple command-line interface and a straightforward Python library.

Installation

Install rune-512 from PyPI:

pip install rune-512

Usage

Command-Line Interface

The package provides a CLI for easy encoding and decoding from your terminal.

Encoding

To encode a string:

python -m rune_512 encode "hello world"
# Output: ⣦◩⣐▕╣⣆◤⠝▷╲⣘▐

To encode a hex string, use the --hex flag:

python -m rune_512 encode --hex "deadbeef"
# Output: ⢜╓▽⢶◷⣰

You can also pipe data from stdin:

echo "some data" | python -m rune_512 encode
# Output: ⠘⡴◍╻⣖⢤⠙⠰╴⣂

Decoding

To decode a rune-512 string:

python -m rune_512 decode "⣦◩⣐▕╣⣆◤⠝▷╲⣘▐"
# Output: hello world

To decode to a hex string, use the --hex flag:

python -m rune_512 decode --hex "⢜╓▽⢶◷⣰"
# Output: deadbeef

Library

You can also use rune-512 as a library in your Python projects.

Encoding

To encode a byte string:

from rune_512 import encode

payload = b'hello world'
encoded_string = encode(payload)
print(encoded_string)
# Output: ⣦◩⣐▕╣⣆◤⠝▷╲⣘▐

Decoding

To decode a string:

from rune_512 import decode

encoded_string = '⣦◩⣐▕╣⣆◤⠝▷╲⣘▐'
try:
    payload, codepoints_consumed = decode(encoded_string)
    print(payload)
    # Output: b'hello world'
    print(f"Consumed {codepoints_consumed} codepoints.")
    # Output: Consumed 12 codepoints.
except ValueError as e:
    print(f"Decoding failed: {e}")

The decode function returns a tuple containing the decoded bytes and the number of Unicode codepoints consumed from the input string. This is useful for parsing data from streams or larger text blocks that may contain other information. Since the payload length is not encoded in the data, rune-512 is designed for stream-based decoding. The decoder reads characters until it encounters one outside its alphabet, and the returned count helps you know how much of the input was part of the encoded data.

It is up to the user to decide on a scheme for indicating the start of a valid encoded payload inside of a larger body of text.

How It Works

A rune-512 encoded string consists of two parts:

  1. Header: An 18-bit section containing a 17-bit checksum derived from the SHA-256 hash of the original payload and a parity bit for padding disambiguation.
  2. Payload: The binary data, packed into 9-bit chunks.

Each 9-bit chunk is mapped to a character in the 512-character alphabet. This structure ensures that the data is both compact and verifiable.

Limitations

rune-512 is designed for encoding small to medium-sized binary payloads in text-based environments. It is not intended for all use cases. Please consider the following limitations:

  • Security: The SHA-256-derived checksum only protects against accidental data corruption. It does not provide cryptographic security. Malicious actors can easily tamper with the data and forge a valid checksum. For applications requiring tamper-resistance, use a solution with cryptographic signatures or MACs (e.g., HMAC-SHA256).

  • Scalability: The current implementations load the entire payload into memory. This makes them unsuitable for very large files, as it can lead to high memory usage and potential performance issues. In a server environment, processing excessively large inputs could pose a Denial of Service (DoS) risk. It is recommended to validate and limit input sizes before decoding.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

rune_512-0.3.1.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

rune_512-0.3.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file rune_512-0.3.1.tar.gz.

File metadata

  • Download URL: rune_512-0.3.1.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for rune_512-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b79bc832a1bc756186c5d9f201aaf128e338d3cfad507dbcec668dfaca80e980
MD5 368157ab53b40577feb2d9bb07e35516
BLAKE2b-256 212ce72a26014d3cb555fbac1af229317892e463a627405f447c10336b76786f

See more details on using hashes here.

File details

Details for the file rune_512-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: rune_512-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for rune_512-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61482711568812eb92ce6bf39ae6c73fd942a31dbe698822464e92f0bad14c02
MD5 f0405bf1da27d7028b5ec18bec55e331
BLAKE2b-256 593646416a5dcbc533a9e9e262f08b949561abc497c6350b34568b657cffe98f

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