High speed Base58 encoding using GMP with BigInt and MD5 support
MIT License
High speed Base58 encoding using GMP with MD5 support and transcoding between Flickr, Bitcoin, Ripple and GMP alphabets.
Add base58_gmp
to Gemfile
and then run bundle
:
$ echo "gem 'base58_gmp'" >> Gemfile
$ bundle
$ gem install base58_gmp
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
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.
This class requires GMP 4.2.0 or above. Prior versions are limited to Base36.
This library supports and is tested against the following Ruby implementations:
See CHANGELOG.md
Project Repo
Flickr post introducing Base58:
Bitcoin wiki Base58 article:
GMP:
John Wang - http://johnwang.com
Some test examples courtesy Fraser Speirs' Base58Encoder Objective-C class, http://gist.github.com/101674.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Base58 GMP Ruby is available under an MIT-style license. See LICENSE.txt for details.
Base58 GMP Ruby © 2011-2016 by John Wang