Base58 is a Ruby library/gem for converting ints to and from base58.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 4b784dc May 16, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib change binary_to_base58 to use unpack for consistency with base58_to_… Jan 10, 2018
test add test and fix for base58_to_binary bug Jan 10, 2018
.gitignore Initial commit. Apr 25, 2009
CHANGELOG Version 0.2.3. May 16, 2018
MIT-LICENSE Turns out it is 2018 already. Jan 5, 2018 Version 0.2.1. Jan 11, 2018
Rakefile Version 0.2.3. May 16, 2018
VERSION Version 0.2.3. May 16, 2018
base58.gemspec Version 0.2.3. May 16, 2018


Ruby gem for encoding/decoding integers to/from Base58. Supports Flickr, Bitcoin, and Ripple alphabets.


Converting an integer into a Base58 string:

Base58.int_to_base58(12345) # => "4ER"

Converting a Base58 string to the represented integer:

Base58.base58_to_int("A2Ph") # => 6639914

Converting a binary into a Base58 string:

Base58.binary_to_base58("\xCE\xE99\x86".force_encoding('BINARY')) # => "6hKMCS"

Converting a Base58 string to the represented binary:

Base58.base58_to_binary("6hKMCS") # => "\xCE\xE99\x86"


The package can be installed by adding scatter_swap to your list of dependencies in mix.exs:

gem install base58

Or add it to your Gemfile

gem 'base58'

The run bundle install.

What is Base58?

From Wikipedia:

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.

Supported Alphabets

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 Base58.int_to_base58 and Base58.base58_to_int.

Base58.int_to_base58(12345, :bitcoin)

:flickr is the default if no second argument is passed.


Identifier: :flickr

This is the default alphabet. Used to generate Flickr short URLs. The order of it's characters is numeric, lowercase-alpha, uppercase-alpha.



Identifier: :bitcoin

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.


Identifier: :ripple

The alphabet used by the Ripple protocol. The order of the characters were chosen such that the low values match the primitives of the protocol.


Leading Zeroes

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*')

Base58.binary_to_base58(bitcoin_address_bin, :bitcoin, true) # => 111111111143c9JGph3DZ


Source repository is on Github, please file issues and pull requests there.


Documentation can be found online at

Alternatively, you can generate docs from the project root with:

rake rdoc


Copyright and Licence

Copyright (c) 2009 - 2018, Douglas F Shearer.

Base58 is licensed under the MIT Licence.