Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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