Skip to main content

Encode and decode base56 data.

Project description

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

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

base56-0.1.1.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

base56-0.1.1-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file base56-0.1.1.tar.gz.

File metadata

  • Download URL: base56-0.1.1.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for base56-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2f96cbe8d46c96a86b320cc44377f11f429cadd4969a44d3e40320cfe8efb592
MD5 dcc544b73144f5d0f1f919ec243e015b
BLAKE2b-256 49f2c8832eb56bb28f2e415a153e4807457401dd7daa1396b75b6a04b5473907

See more details on using hashes here.

File details

Details for the file base56-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: base56-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for base56-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2c7ed0bdbefa2bec31f066c194b77b84706ad7cd1bfffdb0d21101ef4f395460
MD5 b43ec2ef8cd4d60a515498ea2b427adf
BLAKE2b-256 b5f9363512a93f86cde2d03d25042d0476fde2dd22e41781769e11975c2c4ea6

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