Ruby gem for encoding/decoding integers to/from Base58. Supports Flickr, Bitcoin, and Ripple alphabets.
Converting an integer into a Base58 string:
.(12345) # => "4ER"
Converting a Base58 string to the represented integer:
.("A2Ph") # => 6639914
Converting binary into a Base58 string:
.("\xCE\xE99\x86".force_encoding('BINARY')) # => "6hKMCS"
Converting a Base58 string to the represented binary:
.("6hKMCS") # => "\xCE\xE99\x86"
base58 with the following command
gem install base58
Or add it to your Gemfile
What is Base58?
Base58 is a group of binary-to-text encoding schemes used to represent large integers as alphanumeric text. It is similar to Base64 but has been modified to avoid both non-alphanumeric characters and letters which might look ambiguous when printed. It is therefore designed for human users who manually enter the data, copying from some visual source, but also allows easy copy and paste because a double-click will usually select the whole string.
Base58 alphabets are made up of the characters a-z, A-Z, and 0-9, with visually ambiguous characters (0, O, I, l) removed.
This library supports three of the most common Base58 alphabets, which have identical, but differently sorted characters.
Alphabets can be selected by passing a symbol to the second argument of
:flickr is the default if no second argument is passed.
This is the default alphabet. Used to generate Flickr short URLs. The order of it's characters is numeric, lowercase-alpha, uppercase-alpha.
The alphabet used by the Bitcoin protocol. The order of it's characters is numeric, uppercase-alpha, lowercase-alpha.
See the "Leading Zeros" section for enabling full Bitcoin-style leading-zeros support.
Some protocols, such as Bitcoin, require that leading zeros be encoded. Passing
true to the third argument of binary_to_base58()` will enable this behaviour.
bitcoin_address_hex = '00000000000000000000123456789ABCDEF0' bitcoin_address_bin = [bitcoin_address_hex].pack('H*') .(bitcoin_address_bin, :bitcoin, true) # => 111111111143c9JGph3DZ
Source repository is on Github, please file issues and pull requests there.
Documentation can be found online at RubyDoc.info.
Alternatively, you can generate docs from the project root with:
- Joel Nordell for various Bitcoin/Ripple support features.
- Jim Myhrberg for argument checking and method aliases.
Copyright and Licence
Copyright (c) 2009 - 2018, Douglas F Shearer.
Base58 is licensed under the MIT Licence.