All Projects → shengdoushi → base58

shengdoushi / base58

Licence: MIT License
fast/simple Base58 encoding/decoding in golang.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to base58

base58
Fast implementation of base58 encoding on golang.
Stars: ✭ 121 (+210.26%)
Mutual labels:  fast, base58
contentfully
A simple but performant REST client for Contentful.
Stars: ✭ 13 (-66.67%)
Mutual labels:  fast
ImmediateReflection
.NET library that aims to provide faster usage of C# reflection features. Especially the usage of constructor and members accessors (get/set). It also provides an ObjectWrapper object allowing to use Reflection in a faster way. And finally it offers the possibility to create strongly typed delegates.
Stars: ✭ 30 (-23.08%)
Mutual labels:  fast
DynAdjust
Least squares adjustment software
Stars: ✭ 43 (+10.26%)
Mutual labels:  fast
komihash
Very fast, high-quality hash function (non-cryptographic, C) + PRNG
Stars: ✭ 68 (+74.36%)
Mutual labels:  fast
litchi
这是一款分布式的java游戏服务器框架
Stars: ✭ 97 (+148.72%)
Mutual labels:  fast
ormsgpack
Msgpack serialization/deserialization library for Python, written in Rust using PyO3 and rust-msgpack. Reboot of orjson. msgpack.org[Python]
Stars: ✭ 88 (+125.64%)
Mutual labels:  fast
AutoMagic
A magically fast, lightweight and customizable javascript library.
Stars: ✭ 16 (-58.97%)
Mutual labels:  fast
jobflow
runs stuff in parallel (like GNU parallel, but much faster and memory-efficient)
Stars: ✭ 67 (+71.79%)
Mutual labels:  fast
chclient
Fast http client for SELECT queries in clickhouse
Stars: ✭ 44 (+12.82%)
Mutual labels:  fast
route
A fast router for PHP
Stars: ✭ 27 (-30.77%)
Mutual labels:  fast
qpage
👨‍💻 Free Project For Creating Academic Homepage Without Any Code In 3min
Stars: ✭ 87 (+123.08%)
Mutual labels:  fast
Maat
Validation and transformation library powered by deductive ascending parser. Made to be extended for any kind of project.
Stars: ✭ 27 (-30.77%)
Mutual labels:  fast
fastweb
fastweb is a web-server integration solution. It based on tornado, celery, thrift.
Stars: ✭ 17 (-56.41%)
Mutual labels:  fast
koa-rest-router
Most powerful, flexible and composable router for building enterprise RESTful APIs easily!
Stars: ✭ 67 (+71.79%)
Mutual labels:  fast
TypeKitchen
TypeKitchen is a set of small libraries for fast metaprogramming in .NET Standard.
Stars: ✭ 14 (-64.1%)
Mutual labels:  fast
fundamental-tools
Web applications with ABAP, done simple.
Stars: ✭ 42 (+7.69%)
Mutual labels:  fast
python-libmf
No description or website provided.
Stars: ✭ 24 (-38.46%)
Mutual labels:  fast
dowels
🔨 a tiny but powerful javascript library that performs client-side routing, templating, and REST API communication to help you get your single-page web applications running in seconds
Stars: ✭ 13 (-66.67%)
Mutual labels:  fast
amber-router
A URL Routing shard.
Stars: ✭ 16 (-58.97%)
Mutual labels:  fast

Travis CI GoDoc Go Report Card

Chinese document 中文文档参看 README_zh.md

Features

  • Fast and lightweight
  • API simple
  • support some common alphabet: Bitcoin, IPFS, Flickr, Ripple
  • can custom alphabet
  • custom alphabet can be unicode string

API Doc

Godoc

base58 algorithm

Wikipedia:

From Wikipedia, the free encyclopedia 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.

Compared to Base64, the following similar-looking letters are omitted: 0 (zero), O (capital o), I (capital i) and l (lower case L) as well as the non-alphanumeric characters + (plus) and / (slash). In contrast to Base64, the digits of the encoding do not line up well with byte boundaries of the original data. For this reason, the method is well-suited to encode large integers, but not designed to encode longer portions of binary data. The actual order of letters in the alphabet depends on the application, which is the reason why the term “Base58” alone is not enough to fully describe the format. A variant, Base56, excludes 1 (one) and o (lowercase o) compared to Base 58.

Base58Check is a Base58 encoding format that unambiguously encodes the type of data in the first few characters and includes an error detection code in the last few characters.[1]

Installation

go get -u github.com/shengdoushi/base58

API

just 2 API:

// encode with custom alphabet
func Encode(input []byte, alphabet *Alphabet)string

// Decode with custom alphabet
func Decode(input string, alphabet *Alphabet)([]byte, error)

Usage

import "github.com/shengdoushi/base58"
	
// Alphabet
// myAlphabet := base58.BitcoinAlphabet // bitcoin address's alphabet
myAlphabet := base58.NewAlphabet("ABCDEFGHJKLMNPQRSTUVWXYZ123456789abcdefghijkmnopqrstuvwxyz") // custom alphabet, must 58 length
	
// encode to string 
var encodedStr string = base58.Encode([]byte{1,2,3,4}, myAlphabet)
	
// decode to []byte 
var encodedString string = "Xsdfjs123D"
decodedBytes, err := base58.Decode(encodedString, myAlphabet)
if err != nil {
	// error occurred
}

Example

package main

import (
	"fmt"
	"github.com/shengdoushi/base58"
)

func main(){
	// use bitcoin alphabet, just same as: base58.NewAlphabet("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
	myAlphabet := base58.BitcoinAlphabet
	
	// encode
	input := []byte{0,0,0,1,2,3}
	var encodedString string = base58.Encode(input, myAlphabet)
	fmt.Printf("base58encode(%v) = %s\n", input, encodedString)
	
	// decode
	decodedBytes, err := base58.Decode(encodedString, myAlphabet)
	if err != nil { // error occurred when encodedString contains character not in alphabet
		fmt.Println("error occurred: ", err)
	}else{
		fmt.Printf("base58decode(%s) = %v\n", encodedString, decodedBytes)
	}	
}

The example will output:

base58encode([0 0 0 1 2 3]) = 111Ldp
base58decode(111Ldp) = [0 0 0 1 2 3]

Alphabet

This package provide some common alphabet(copyed from https://en.wikipedia.org/wiki/Base58):

// Bitcoin: 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
base58.BitcoinAlphabet
// IPFS: 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
base58.IPFSAlphabet
// Ripple: rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz
base58.RippleAlphabet
// Flickr: 123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ
base58.FlickrAlphabet

Or you can use custom alphabet, the alphabet's length (runes's length) must be 58. The alphabet can use unicode string.

myAlphabet := base58.NewAlphabet("一二三四五六七八九十壹贰叁肆伍陆柒捌玖零拾佰仟万亿圆甲乙丙丁戊己庚辛壬癸子丑寅卯辰巳午未申酉戌亥金木水火土雷电风雨福")

LICENSE

Under the MIT LICENSE, see the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].