Skip to main content

BatteryHorse

Encode and decode text as English sentences. The name is inspired by this xkcd comic.

API

The batteryhorse module exposes three functions:

encode_data(data: bytes) -> str

Encode the given data into one or more English phrases/sentences. Uses Wordnet from the NLTK library to create sentences in the following format: VERB NOUN ADJECTIVE CONJUNCTION ADJECTIVE. If the bytes can be encoded into fewer parts of speech then the rest will be truncated.

decode_data(data: str, length: int) -> bytes

Decode a string of sentences or phrases back into the original bytes. Also requires the size of the output bytes

create_secret(size=3: int) -> bytes

Creates a random passphrase by using random words from the Wordnet. Size specifies the number of words to use

Examples

A basic example that encodes some data

>>> import batteryhorse
>>> batteryhorse.encode_data(b'TEST')
'Unitise annum abasic'

An example showing encoding and decoding data

>>> from hashlib import sha1
>>> import batteryhorse
>>> 
>>> digest = sha1('test'.encode('utf-8')).digest()
>>> 
>>> batteryhorse.encode_data(digest)
'Birdnest vara lobed or orthoptic. Wow fencing orthogonal yet anthropomorphic. Scranch rifadin anosmatic'
>>> 
>>> batteryhorse.decode_data('Birdnest vara lobed or orthoptic. Wow fencing orthogonal yet anthropomorphic. Scranch rifadin anosmatic', len(digest))
b'\xa9J\x8f\xe5\xcc\xb1\x9b\xa6\x1cL\x08s\xd3\x91\xe9\x87\x98/\xbb\xd3'
>>> print(digest)
b'\xa9J\x8f\xe5\xcc\xb1\x9b\xa6\x1cL\x08s\xd3\x91\xe9\x87\x98/\xbb\xd3'

Command Line

BatteryHorse is also available on the command line.

  --encode         Accept data to be encoded from STDIN
  --decode         Accept data to be decoded from STDIN
  --generate       Generate a random secret
  --length LENGTH  Specify the length of secret or data to be decoded

And as an example

$ echo "TEST" | python -m batteryhorse --encode
Bare gyrostabilizer amygdaloidal

Uses

The original intention of this library was to create a new way of sharing fingerprints of public keys.

Limitations

Although Batteryhorse can encode data of arbitary lengths it does no padding of the data beforehand resulting in some sentences that may not be complete.

Additionally, since the length of the original data is not encoded the decode function must take the length as a parameter.

Release files for BatteryHorse 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BatteryHorse 1.0.0
File Size Uploaded
BatteryHorse-1.0.0.tar.gz 10.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for BatteryHorse 1.0.0
File Interpreter ABI Platform
BatteryHorse-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.5 MB

Release files / BatteryHorse-1.0.0.tar.gz

Download URL BatteryHorse-1.0.0.tar.gz
Size 10.7 MB
Tags Source
SHA-256 checksum
How to use checksums
ae39bc68785acf7ba1b7dd91ec0a7449ee6db7dd24dbb2ee2007ed2d3cff0c47
BLAKE2b-256 checksum
How to use checksums
a2d2676747c2c535a1c732fcb99e3789b794c88d2e634a3abf2bc55832ab7218
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

Release files / BatteryHorse-1.0.0-py3-none-any.whl

Download URL BatteryHorse-1.0.0-py3-none-any.whl
Size 10.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
fd6e1af601b399973a085355f0202ee1e7453c141549ded7edd0a357e7e77f29
BLAKE2b-256 checksum
How to use checksums
df1859d326d88c30e8505edd0dec8102ae6a742077c35fab655115717cca2dc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page