Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nicksnyder/basen
A base62 and base58 encoding library for Go
https://github.com/nicksnyder/basen
base58 base62 decoding encoding go
Last synced: 2 months ago
JSON representation
A base62 and base58 encoding library for Go
- Host: GitHub
- URL: https://github.com/nicksnyder/basen
- Owner: nicksnyder
- License: mit
- Created: 2019-04-18T05:12:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-04-30T22:23:44.000Z (over 5 years ago)
- Last Synced: 2024-06-19T20:49:35.643Z (6 months ago)
- Topics: base58, base62, decoding, encoding, go
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 14
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# basen
[![GoDoc](http://godoc.org/github.com/nicksnyder/basen?status.svg)](http://godoc.org/github.com/nicksnyder/basen) [![Build Status](https://travis-ci.org/nicksnyder/basen.svg?branch=master)](http://travis-ci.org/nicksnyder/basen) [![codecov](https://codecov.io/gh/nicksnyder/basen/branch/master/graph/badge.svg)](https://codecov.io/gh/nicksnyder/basen) [![Report card](https://goreportcard.com/badge/github.com/nicksnyder/basen)](https://goreportcard.com/report/github.com/nicksnyder/basen)
Package basen implements a radix encoding/decoding scheme, defined by a n-character alphabet.
```go
import "github.com/nicksnyder/basen"
```## base62
Base62 encoding encodes data using the character set `0-9A-Za-z`. It is useful for generating strings that are safe to include in URLs, and allows easy copy and paste because a double-click will usually select the whole string.
Encode:
```go
encoded := basen.Base62Encoding.EncodeToString([]byte("Hello"))
fmt.Println(encoded) // 5TP3P3v
```Decode:
```go
decoded, _ := basen.Base62Encoding.DecodeString("5TP3P3v")
fmt.Println(string(decoded)) // Hello
```## base58
[Base58 encoding](https://en.wikipedia.org/wiki/Base58) is base62 encoding modified to avoid letters which might look ambiguous when printed (i.e. `0`, `O`, `I`, `l`). This reduces the risk of errors when a human is manually copying from some visual source.
Encode:
```go
encoded := basen.Base58Encoding.EncodeToString([]byte("Hello"))
fmt.Println(encoded) // 9Ajdvzr
```Decode:
```go
decoded, _ := basen.Base58Encoding.DecodeString("9Ajdvzr")
fmt.Println(string(decoded)) // Hello
```