Base58 GMP Ruby

Gem Version Build Status Coverage Status Dependency Status Code Climate Scrutinizer Code Quality Downloads Docs License

Stories in Ready

High speed Base58 encoding using GMP with MD5 support and transcoding between Flickr, Bitcoin, Ripple and GMP alphabets.

Installation

Via Bundler

Add base58_gmp to Gemfile and then run bundle:

$ echo "gem 'base58_gmp'" >> Gemfile
$ bundle

Via RubyGems

$ gem install base58_gmp

Usage

Alphabet can be specified using symbol or string.

require 'base58_gmp'

# Encode Int as Base58
Base58GMP.encode 12345                          # => 4ER

# Encode GMP::Z Int as Base58
Base58GMP.encode GMP::Z(12345)                  # => 4ER

# Encode as Base58 using alternate alphabets
Base58GMP.encode 12345, :bitcoin                # => 4fr
Base58GMP.encode 12345, :gmp                    # => 3cn

# Encode as Base58 using alternate alphabets using string
Base58GMP.encode 12345, 'bitcoin'               # => 4fr
Base58GMP.encode 12345, 'gmp'                   # => 3cn

# Decode Base58 as GMP::Z Integer
Base58GMP.decode '4ER'                          # => 12345

# Decode Base58 as GMP::Z Integer using alternate alphabets
Base58GMP.decode '4fr', :bitcoin                # => 12345
Base58GMP.decode '3cn', :gmp                    # => 12345

# MD5 Base58 Digest
Base58GMP.md5 '[email protected]'                     # => w6fdCRXnUXyz7EtDn5TgN9

# MD5 Base58 Digest with left padding for consistent length
Base58GMP.md5 '[email protected]', :flickr, pad: true # => w6fdCRXnUXyz7EtDn5TgN9

# Convert between alphabets
Base58GMP.from_to '123456789abcdefghijk', :flickr, :gmp # => 0123456789ABCDEFGHIJ
Base58GMP.from_to '0123456789ABCDEFGHIJ', :gmp, :flickr # => 123456789abcdefghijk

Notes

Base58 Implementations - Flickr, Bitcoin and GMP

This class supports the Base58 alphabets used by Flickr, Bitcoin and GMP. The Flickr alphabet is the default and used when no alphabet is provided.

Alphabet Character Set
Flickr [0-9a-zA-Z] excluding [0OIl]
Bitcoin [0-9A-Za-z] excluding [0OIl]
Ripple rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz
GMP [0-9A-Za-v]

The encode, decode and md5 methods support an alphabet parameter which can be set to the supported alphabets ['bitcoin', 'flickr', 'gmp'] to indicate the value to be encoded or decoded.

GMP

This class requires GMP 4.2.0 or above. Prior versions are limited to Base36.

Supported Ruby Versions

This library supports and is tested against the following Ruby implementations:

  1. Ruby 2.3.0
  2. Ruby 2.2.0
  3. Ruby 2.1.0
  4. Ruby 2.0.0

Change Log

See CHANGELOG.md

Project Repo

Flickr post introducing Base58:

Bitcoin wiki Base58 article:

GMP:

Credits

John Wang - http://johnwang.com

Some test examples courtesy Fraser Speirs' Base58Encoder Objective-C class, http://gist.github.com/101674.

Contributing

  1. Fork it (http://github.com/grokify/base58-gmp-ruby/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

Base58 GMP Ruby is available under an MIT-style license. See LICENSE.txt for details.

Base58 GMP Ruby © 2011-2016 by John Wang