OSDN Git Service

add package
[bytom/vapor.git] / vendor / github.com / mr-tron / base58 / README.md
1 # Fast Implementation of Base58 encoding
2 [![GoDoc](https://godoc.org/github.com/mr-tron/base58?status.svg)](https://godoc.org/github.com/mr-tron/base58)  [![Go Report Card](https://goreportcard.com/badge/github.com/mr-tron/base58)](https://goreportcard.com/report/github.com/mr-tron/base58)
3 [![Used By](https://sourcegraph.com/github.com/mr-tron/base58/base58/-/badge.svg)](https://sourcegraph.com/github.com/mr-tron/base58?badge)
4
5 Fast implementation of base58 encoding in Go. 
6
7 Base algorithm is copied from https://github.com/trezor/trezor-crypto/blob/master/base58.c
8
9 ## Benchmark
10 Trivial - encoding via big.Int (over libraries use this implemenation)
11 Fast - optimized algorythm from trezor
12
13 ```
14 BenchmarkTrivialBase58Encoding-4          200000             10602 ns/op  
15 BenchmarkFastBase58Encoding-4            1000000              1637 ns/op
16 BenchmarkTrivialBase58Decoding-4          200000              8316 ns/op
17 BenchmarkFastBase58Decoding-4            1000000              1045 ns/op
18 ```
19 Encoding - **faster by 6 times**
20
21 Decoding - **faster by 8 times**
22
23 ## Usage example
24
25 ```go
26
27 package main
28
29 import (
30         "fmt"
31         "github.com/mr-tron/base58"
32 )
33
34 func main() {
35
36         encoded := "1QCaxc8hutpdZ62iKZsn1TCG3nh7uPZojq"
37         num, err := base58.Decode(encoded)
38         if err != nil {
39                 fmt.Printf("Demo %v, got error %s\n", encoded, err)     
40         }
41         chk := base58.Encode(num)
42         if encoded == string(chk) {
43                 fmt.Printf ( "Successfully decoded then re-encoded %s\n", encoded )
44         } 
45 }
46
47 ```