A pure Go collection of Base58, Base91, Base92… with safety, rigor and performance in mind

BaseXX

Go modules:           Go Reference

import "github.com/teal-finance/BaseXX/base58"
import "github.com/teal-finance/BaseXX/base62"
import "github.com/teal-finance/BaseXX/base91"
import "github.com/teal-finance/BaseXX/base92"
import "github.com/teal-finance/BaseXX/xascii85"
import "github.com/teal-finance/BaseXX/ac/base91"

Characters often used by common BaseXX encodings:

Hexa    0123456789ABCDEF
Base58   123456789ABCDEFGH JKLMN PQRSTUVWXYZabcdefghijk mnopqrstuvwxyz
Base62  0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
Base64  0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/=
Base91  0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/=*-_~.,?!@#$%&()[]{|}<>^:`'
Base92  0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/=*-_~.,?!@#$%&()[]{|}<>^:`'"

Fork of mr-tron/base58

Originally, BaseXX is a fork of https://github.com/mr-tron/base58 adapted to support other bases:

All these packages, except xascii85, support customized encoding alphabet without any performance tradeoff.

The xascii85 package is just a layer on top of "encoding/ascii85" to provide the same API as the other packages.

Common interface

All these packages aim to provide the following API:

func NewEncoding(alphabet string) *Encoding

interface Encoding {
    Encode(bin []byte) []byte
    Decode(ascii []byte) ([]byte, error)

    EncodeToString(bin []byte) string
    DecodeString(ascii string) ([]byte, error)

    EncodedLen(n int) int
    DecodedLen(n int) int
}

Faster than unix-world/smartgo

BaseXX is very similar to the project https://github.com/unix-world/smartgo from Radu Ovidiu Ilies who has adapted https://github.com/akamensky/base58 to support any base.

BaseXX shares with SmartGo the ability to quickly create new base encoders, by copying source files and changing the alphabet.

The main interest of BaseXX compared to SmartGo is the performance: BaseXX is five times faster. See the benchmark results.

Slower than Base91 by Antonino Catinello

This repo contains a copy (almost unmodified) of https://codeberg.org/ac/base91. The latter cannot be used because the module name "catinello.eu/base91" is not reachable (tested in May 2022).

The implementation of Antonino Catinello is much faster than BaseXX/base91: The Base91 by Antonino encodes six times faster, and decodes twice faster. See the benchmark results

However his Base91 implementation does not allow to change the alphabet (but this is possible with some adaptations).

Compliance with cookie token standards

The default alphabet of BaseXX/base58, BaseXX/base62, BaseXX/base91 and BaseXX/base92 conforms with the cookie token constraints:

  • characters from 0x20 (space) to 0x7E (~) included
  • except three characters: " ; and \

The two other encoders, BaseXX/xascii85 and BaseXX/ac/base91 do not support cookie token encoding.

Usage

In the following example replace base92 by base58, base62, base91 (or xascii85).

package main

import "github.com/teal-finance/BaseXX/base92"

func main() {
    // Encode any binary data
    bin := []byte{12, 23, 24, 45, 56, 67, 78, 89}
    str := base92.Encode(bin)

    // Decode back
    bin, err := base92.Decode(str)
    if err != nil {
        panic(err)
    }

    // Use custom alphabet, not applicable for xascii85

    var noSpace = base92.NewEncoding(
        "!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO" +
        "PQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~")

    txt := noSpace.EncodeToString(bin)
    bin, err = noSpace.DecodeString(txt)
}

Benchmark

The benchmark shows this BaseXX project is almost faster than the original project on Base58.

$ go test -run=NO -bench=. -benchmem github.com/teal-finance/BaseXX/...
goos: linux
goarch: amd64
pkg: github.com/teal-finance/BaseXX/ac/base91
cpu: AMD Ryzen 9 3900X 12-Core Processor            
BenchmarkEncode-24           234           5098065 ns/op         6642443 B/op         34 allocs/op
BenchmarkDecode-24           217           5285605 ns/op         5241612 B/op         33 allocs/op
PASS
ok      github.com/teal-finance/BaseXX/ac/base91        3.456s
?       github.com/teal-finance/BaseXX/ac/base91/cmd/base91     [no test files]
goos: linux
goarch: amd64
pkg: github.com/teal-finance/BaseXX/base58
cpu: AMD Ryzen 9 3900X 12-Core Processor            
BenchmarkEncode-24                       1000000              1706 ns/op              96 B/op          2 allocs/op
BenchmarkEncodeMrTronBase58-24           1000000              1802 ns/op              96 B/op          2 allocs/op
BenchmarkDecode-24                       1611724               733.3 ns/op           127 B/op          2 allocs/op
BenchmarkDecodeMrTronBase58-24           1632877               741.9 ns/op           127 B/op          2 allocs/op
PASS
ok      github.com/teal-finance/BaseXX/base58   7.445s
goos: linux
goarch: amd64
pkg: github.com/teal-finance/BaseXX/base62
cpu: AMD Ryzen 9 3900X 12-Core Processor            
BenchmarkEncode-24        908791              1360 ns/op              48 B/op          1 allocs/op
BenchmarkDecode-24       1524541               759.1 ns/op           127 B/op          2 allocs/op
PASS
ok      github.com/teal-finance/BaseXX/base62   4.193s
goos: linux
goarch: amd64
pkg: github.com/teal-finance/BaseXX/base91
cpu: AMD Ryzen 9 3900X 12-Core Processor            
BenchmarkEncode-24               1000000              1383 ns/op              48 B/op          1 allocs/op
BenchmarkEncodeACBase91-24       2823261               422.7 ns/op           168 B/op          5 allocs/op
BenchmarkDecode-24               1709204               691.3 ns/op           124 B/op          2 allocs/op
BenchmarkDecodeACBase91-24       2849089               416.9 ns/op           104 B/op          4 allocs/op
PASS
ok      github.com/teal-finance/BaseXX/base91   6.562s
goos: linux
goarch: amd64
pkg: github.com/teal-finance/BaseXX/base92
cpu: AMD Ryzen 9 3900X 12-Core Processor            
BenchmarkEncode-24                        891435              1349 ns/op              48 B/op          1 allocs/op
BenchmarkEncodeSmartgoBase92-24           140588              8100 ns/op            1377 B/op         78 allocs/op
BenchmarkDecode-24                       1795351               665.8 ns/op           122 B/op          2 allocs/op
BenchmarkDecodeSmartgoBase92-24           335845              3459 ns/op             232 B/op          8 allocs/op
PASS
ok      github.com/teal-finance/BaseXX/base92   6.344s
?       github.com/teal-finance/BaseXX/encoding [no test files]
PASS
ok      github.com/teal-finance/BaseXX/xascii85 0.002s

Feedback

If you have some suggestions, or need a new feature, please contact us, using the issue tracking, or at Teal.Finance[à]pm.me or @TealFinance.

Feel free to propose a Pull Request, your contributions are welcome. 😉

See also

Other similar projects:

Owner
Teal.Finance
Cryptocurrencies Data for All to Verify or to Trade
Teal.Finance
Similar Resources

Rest API to get KVB departures - Written in Go with hexagonal architecture and tracing via OpenTelemetry and Jaeger

KVB API Rest API to get upcoming departures per KVB train station Implemented in Go with hexagonal architecture and tracing via OpenTelemetry and Jaeg

May 7, 2022

Pokemon Unite scoreboard HUD and extra tools running over captured game feeds using the OpenCV video processing API and Client/Server architecture.

Pokemon Unite scoreboard HUD and extra tools running over captured game feeds using the OpenCV video processing API and Client/Server architecture.

unite Pokemon Unite scoreboard HUD and extra tools running over captured game feeds using the OpenCV video processing API. Client (OBS Live) Server Ar

Dec 5, 2022

The wazuh-integratord is a daemon that allows Wazuh to connect to external APIs and alerting tools such as Slack, VirusTotal and PagerDuty.

The wazuh-integratord is a daemon that allows Wazuh to connect to external APIs and alerting tools such as Slack, VirusTotal and PagerDuty.

Apr 22, 2022

MealPlanr is an application dedicated to the trivial and boring task of meal planning 📅 and generating a shopping list 🛒 .

MealPlanr is an application dedicated to the trivial and boring task of meal planning 📅 and generating a shopping list 🛒 .

MealPlanr is an application dedicated to the trivial and boring task of meal planning 📅 and generating a shopping list 🛒 .

Mar 1, 2022

Awspowertoggle - Web UI and API for quickly starting and stopping AWS environments

Awspowertoggle - Web UI and API for quickly starting and stopping AWS environments

aws-power-toggle web UI and API for quickly starting and stopping AWS environmen

Feb 23, 2022

Fast and light-weight API proxy firewall for request and response validation by OpenAPI specs.

Fast and light-weight API proxy firewall for request and response validation by OpenAPI specs.

Open Source API Firewall API Firewall is a high-performance proxy with API request and response validation based on OpenAPI/Swagger schema. It is desi

Jan 8, 2023

Go library to access geocoding and reverse geocoding APIs

GeoService in Go Code Coverage A geocoding service developed in Go's way, idiomatic and elegant, not just in golang. This product is designed to open

Dec 23, 2022

Go library for accessing trending repositories and developers at Github.

Go library for accessing trending repositories and developers at Github.

go-trending A package to retrieve trending repositories and developers from Github written in golang. This package were inspired by rochefort/git-tren

Dec 21, 2022
Comments
  • You opened a ticket with your benchmark. I did measured on my side. results are different ...

    You opened a ticket with your benchmark. I did measured on my side. results are different ...

    I have did my own benchmark and my results are completely different than yours smartgo basexx is a bit faster than yours ...

    https://github.com/unix-world/smartgo/issues/1

Skillshot - A collection of ranking algorithms to be used in matchmaking

Skillshot A collection of ranking algorithms to be used in matchmaking. Openskil

Aug 26, 2022
A collection of cloud security icons :cloud::lock:
A collection of cloud security icons :cloud::lock:

Cloud Security Icons These icons are published under the extremely permissive Creative Commons Zero v1.0 Universal license. Downloads We provide all i

Jan 7, 2023
🌇 High Performance Fibonacci Abstraction Layer + API

Fibonacci High Performance Fibonacci Abstraction Layer and an API.

Nov 2, 2022
Serverless SOAR (Security Orchestration, Automation and Response) framework for automatic inspection and evaluation of security alert
Serverless SOAR (Security Orchestration, Automation and Response) framework for automatic inspection and evaluation of security alert

DeepAlert DeepAlert is a serverless framework for automatic response of security alert. Overview DeepAlert receives a security alert that is event of

Jan 3, 2023
Use AWS SQS as a clipboard to copy and paste across different systems and platforms

sqs_clipboard Use AWS SQS as a clipboard to copy and paste across different systems and platforms. Clipboard contents are encrypted in transit and at

Oct 16, 2022
A API scanner written in GOLANG to scan files recursively and look for API keys and IDs.

GO FIND APIS _____ ____ ______ _____ _ _ _____ _____ _____ _____ / ____|/ __ \ | ____|_ _| \ | | __ \ /\ | __ \_

Oct 25, 2021
A simple Go utility to display track information from, and send commands to, spotifyd from Tiling Window Managers like Sway and i3
A simple Go utility to display track information from, and send commands to, spotifyd from Tiling Window Managers like Sway and i3

Untitled Spotifyd Controller A simple Go utility to display track information from, and send commands to, spotifyd from Tiling Window Managers like Sw

Mar 8, 2022
planet is a blockchain built using Cosmos SDK and Tendermint and created with Starport.

planet planet is a blockchain built using Cosmos SDK and Tendermint and created with Starport. Get started starport chain serve serve command install

Oct 31, 2021
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.
AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

AWS credential_process utility to assume AWS IAM Roles with Yubikey Touch and Authenticator App TOPT MFA to provide temporary session credentials; With encrypted caching and support for automatic credential refresh.

Dec 20, 2022
Todo-list - In this project using golang and mySql to create todo-list to Add and remove
Todo-list - In this project using golang and mySql to create todo-list to Add and remove

TODO-Fullstack-App-Go-Gin-Postgres-React This fullstack application creates a TODO List Web Page using the Go/Gin/Postgres/React Stack. Starting the a

Apr 7, 2022