Skip to main content

base56

Human-readable binary encoding base56.

Base56 is a variant of Base58 encoding which further sheds the '1' and the lowercase 'o' characters in order to minimise the risk of fraud and human-error.

Base58 is similar to Base64, but modified to avoid both non-alphanumeric characters (+ and /) and letters that might look ambiguous when printed (0 – zero, I – capital i, O – capital o and l – lower-case L). Base58 is used to represent bitcoin addresses.[citation needed] Some messaging and social media systems break lines on non-alphanumeric strings. This is avoided by not using URI reserved characters such as +.

See also:

Technical details

base56 translates the binary values from 0-55 to their counterpart in the following alphabet: 23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz

Usage

>>> from base56 import b56encode, b56decode
>>> b56encode(b"Hello World!")
'JjTDmGcemeMrgbs73'
>>> b56decode('JjTDmGcemeMrgbs73')
b'Hello World!'

Compatibility

We have different alphabets defined because the Go package and other packages use different alphabets.

>>> from base56 import PY3, GO_STD, GO_ALT, DEFAULT
>>> DEFAULT == PY3
True
>>> DEFAULT
Alphabet(b'23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz')
>>> DEFAULT.b56encode(b"Hello World!") # same as above
'JjTDmGcemeMrgbs73'
>>> GO_STD.b56decode(GO_STD.b56encode(b"Hello World!")) # from the Go implementation
b'Hello World!'
>>> GO_ALT.b56decode(GO_ALT.b56encode(b"Hello World!")) # from the PHP/Java implementation
b'Hello World!'

Skipping Characters

Characters that are not in the set can be skipped. By default, space characters are skipped.

>>> b56decode('JjTDm    GcemeMrgbs73\n')
b'Hello World!'
>>> b56decode('JjTDm    GcemeMrgbs73\n', skip=" \n")
b'Hello World!'

Ambiguity

If characters are ambiguous, they will be treated as the same characters. This only happens if they are included in the alphabet.

>>> GO_STD.decode("o2")  # lowercase letter o
b'p'
>>> GO_STD.decode("02")  # zero
b'p'
>>> GO_STD.decode("O2")  # capital letter o
b'p'
>>> GO_STD.decode("12")  # one
b'q'
>>> GO_STD.decode("I2")  # capital letter i
b'q'

Development

This project is created with tests. To run them, install tox.

tox

To create a new release, push a new tag.

git tag v0.1.0
git push origin v0.1.0

Changelog

  • v0.1.1: Add ambiguity support for decoding
  • v0.1.0: Initial release: Alphabets, encode, decode

Release files for base56 0.1.1

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

Source distribution (sdist)

Source distribution for base56 0.1.1
File Size Uploaded
base56-0.1.1.tar.gz 21.5 kB Details

Built distribution (wheel)

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

Total release size: 44.2 kB

Release files / base56-0.1.1.tar.gz

Download URL base56-0.1.1.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2f96cbe8d46c96a86b320cc44377f11f429cadd4969a44d3e40320cfe8efb592
BLAKE2b-256 checksum
How to use checksums
49f2c8832eb56bb28f2e415a153e4807457401dd7daa1396b75b6a04b5473907
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release files / base56-0.1.1-py3-none-any.whl

Download URL base56-0.1.1-py3-none-any.whl
Size 22.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c7ed0bdbefa2bec31f066c194b77b84706ad7cd1bfffdb0d21101ef4f395460
BLAKE2b-256 checksum
How to use checksums
b5f9363512a93f86cde2d03d25042d0476fde2dd22e41781769e11975c2c4ea6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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