crockford

This library implements Crockford's base 32 encoding as defined at https://www.crockford.com/base32.html.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      crockford:
        github: davidkellis/crockford
  2. Run shards install

Usage

There are three methods that make up the API:

require "crockford"

encoded_value = Crockford.encode(123)               # encoded_value = "3V"
decoded_value = Crockford.decode(encoded_value)     # decoded_value = 123

Crockford.encode(-5)                                # raises ArgumentError, "Unable to encode negative values."

Crockford.decode("invalid_value")                   # raises ArgumentError, "Unable to decode ordinal 95."

optional_val = Crockford.decode?("invalid_value")   # optional_val = nil

Contributors