Coder Social home page Coder Social logo

alexislg2 / base32-crockford Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jbittel/base32-crockford

0.0 2.0 0.0 25 KB

A Python implementation of Douglas Crockford's base32 encoding scheme

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

base32-crockford's Introduction

base32-crockford

Warning: this is a fork. 0 and U have been interverted to avoid to have 0 in encoded strings

A Python module implementing the alternate base32 encoding as described by Douglas Crockford at: http://www.crockford.com/wrmg/base32.html.

He designed the encoding to:

  • Be human and machine readable
  • Be compact
  • Be error resistant
  • Be pronounceable

It uses a symbol set of 10 digits and 22 letters, excluding I, L O and U. Decoding is not case sensitive, and 'i' and 'l' are converted to '1' and 'o' is converted to '0'. Encoding uses only upper-case characters.

Hyphens may be present in symbol strings to improve readability, and are removed when decoding.

A check symbol can be appended to a symbol string to detect errors within the string.

Installation

To install, simply run:

pip install base32-crockford

Usage

Basic usage example:

>>> import base32_crockford
>>> base32_crockford.encode(42)
'1A'
>>> base32_crockford.decode('1A')
42
>>> base32_crockford.encode(42, checksum=True)
'1A5'
>>> base32_crockford.decode('1A5', checksum=True)
42
>>> base32_crockford.normalize('La5')
'1A5'

Encode

base32_crockford.encode(n[, checksum=False[, split=0]])

Encode an integer into a symbol string.

When True, optional checksum causes a check symbol to be calculated and appended to the string. This can help detect errors when decoding.

When specified, optional split causes the output string to be divided into clusters of that size separated by hyphens.

Decode

base32_crockford.decode(s[, checksum=False[, strict=False]])

Decode an encoded symbol string.

Optional checksum can be provided as a counterpart to the same argument when encoding. When True, the trailing check symbol is stripped off and validated. If the check symbol validation fails, a ValueError is raised.

When True, optional strict causes a ValueError to be raised if the symbol string requires normalization.

Normalize

base32_crockford.normalize(s[, strict=False])

Normalize an encoded symbol string by applying these transformations:

  1. Remove hyphens
  2. Replace 'I' and 'L' with '1'
  3. Replace 'O' with '0'
  4. Convert all characters to uppercase

Ordinarily this function is automatically used when decoding, but can be utilized independently to clean or validate a symbol string. Invalid characters within the normalized string causes a ValueError to be raised.

When True, optional strict causes a ValueError to be raised if the symbol string requires normalization.

Changelog

Version 0.3.0

  • Add Python 2.6 support
  • Add Python 3.3 and 3.4 support

Version 0.2.0

  • Add optional split parameter when encoding

Version 0.1.0

  • Initial release

base32-crockford's People

Contributors

alexislg2 avatar jbittel avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.