GithubHelp home page GithubHelp logo

azuchi / base58 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dougal/base58

0.0 1.0 0.0 38 KB

Base58 is a Ruby library/gem for converting ints to and from base58.

Home Page: http://rdoc.info/projects/dougal/base58/

License: MIT License

Ruby 100.00%

base58's Introduction

Base58

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

Usage

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 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"

Installation

Install base58 with the following command

gem install base58

Or add it to your Gemfile

gem 'base58'

Then 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.

Flickr

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.

123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ

Bitcoin

Identifier: :bitcoin

The alphabet used by the Bitcoin protocol. The order of it's characters is numeric, uppercase-alpha, lowercase-alpha.

123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

See the "Leading Zeros" section for enabling full Bitcoin-style leading-zeros support.

Ripple

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.

rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz

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

Contributing

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

Documentation

Documentation can be found online at RubyDoc.info.

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

rake rdoc

Credits

Copyright and Licence

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

Base58 is licensed under the MIT Licence.

base58's People

Contributors

dougal avatar joelnordell avatar jimeh avatar kmeyerhofer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.