Home

Awesome

base-x License GitHub Stars GitHub Forks GitHub Watchers Tweet

Build Status

BaseX encoder / decoder for C++

This is a fast base encoder / decoder of any given alphabet.

Example

// example.cc
// g++ -std=c++14 -o example example.cc

#include <iostream>
#include "base_x.hh"

int main() {
    auto encoded = Base58::base58().encode("Hello world!");

    std::cout << encoded << std::endl;
    // => 1LDlk6QWOejX6rPrJ

    return 0;
}

Compilation

Alphabets

See below for a list of commonly recognized alphabets, and their respective base.

BaseFactoryAlphabet
2base2::base2()01
2base8::base8()01234567
11bas11::bas11()0123456789a
16base16::base16()0123456789abcdef
32base32::base32()0123456789ABCDEFGHJKMNPQRSTVWXYZ
36base36::base36()0123456789abcdefghijklmnopqrstuvwxyz
58base58::base58()123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
58base58::bitcoin()123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
58base58::gmp()0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv
58base58::ripple()rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz
58base58::flickr()123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ
62base62::base62()0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
62base62::inverted()0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
64base64::base64()ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
64base64::urlsafe()ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_
66base66::base66()ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~

How it works

It encodes octet arrays by doing long divisions on all significant digits in the array, creating a representation of that number in the new base.

If you need standard hex encoding, or base64 encoding, this module is NOT appropriate.

Author

German Mendez Bravo (Kronuz)

Follow on GitHub Follow on Twitter

License

MIT License. See LICENSE for details.

Copyright (c) 2017 German Mendez Bravo (Kronuz) @ german dot mb at gmail.com