Base58GMP
High speed Base58 encoding using GMP with MD5 support and transcoding between GMP and Flickr implementations.
Installation
Gem Installation
Download and install base58_gmp with the following:
gem install base58_gmp
Usage
require 'rubygems'
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 GMP alphabet
Base58GMP.encode(12345, 'gmp') # => 3cn
# Decode Base58 as GMP::Z Integer
Base58GMP.decode('4ER') # => 12345
# Decode Base58 as GMP::Z Integer using GMP alphabet
Base58GMP.decode('3cn', 'gmp') # => 12345
# MD5 Base58 Digest
Base58GMP.md5('[email protected]') # => w6fdCRXnUXyz7EtDn5TgN9
# Convert between Flickr and GMP
Base58GMP.flickr_to_gmp('123456789abcdefghijk') # => 0123456789ABCDEFGHIJ
Base58GMP.gmp_to_flickr('0123456789ABCDEFGHIJ') # => 123456789abcdefghijk
Notes
Base58 Implementations - Flickr and GMP
This class supports the Base58 implementations used by Flickr and GMP.
The Flickr implementation uses the [0-9a-zA-Z] Base62 alphabet excluding [0OIl] to improve human readability and is described here:
www.flickr.com/groups/api/discuss/72157616713786392/
The GMP implementation uses the [0-9A-Za-v] alphabet.
The encode, decode and md5 methods support an alphabet parameter which can be set to ‘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.
Problems, Comments, Suggestions?
All of the above are most welcome. [email protected]
Credits
John Wang - johnwang.com
Some test examples courtesy Fraser Speirs’ Base58Encoder Objective-C class, gist.github.com/101674.
License
Base58GMP is available under an MIT-style license.
:include: MIT-LICENSE
Warranty
This software is provided “as is” and without any express or implied warranties, including, without limitation, the implied warranties of merchantibility and fitness for a particular purpose.