Giter Club home page Giter Club logo

copper-multibase's Introduction

Copper Multibase Encoder and Decoder.

A Java implementation of Multibase.

Java 8 CI Maven Central License

Features

  • static registry
    • no lookups when encoding
    • direct static access to an encoder
    • configurable set of encodings to support when decoding
  • built-in bases
    • Base2
    • Base16 (lower|upper)
    • Base32 (lower|upper, [no-]padding)
    • Base32Hex (lower|upper, [no-]padding)
    • Base58BTC
    • Base64 ([no-]padding)
    • Base64URL ([no-]padding)
  • no 3rd party dependencies
  • easily extendable

Examples

/* encode an input with Base58BTC */
String encoded = Multibase.BASE_58_BTC.encode(byte[]);

/* get decoder instance initialized with all supported bases */
var decoder = MultibaseDecoder.getInstance();

/* get decoder initialized with custom base(s) */
var decoder = MultibaseDecoder.getInstance(cbases...);

/* decode */
byte[] decoded = decoder.decode(encoded);

/* or check if base is supported  */
Multibase base = decoder.getBase(encoded).orElseThrow(() -> new IllegalArgumentException("Unsupported base."));
byte[] decoded = base.decode(encoded);

/* or directy when only one base is supported */
byte[] decoded = Multibase.BASE_58_BTC.decode(encoded);

/* check if encoded with a base */
if (Multibase.BASE_58_BTC.isEncoded(encoded)) {
  ...
}

/* a cutom base implementation */
var mybase = new Multibase(
                     prefix,   // multibase prefix letter
                     length,   // alphabet length
                     string -> byte[], // decode fnc.
                     byte[] -> string // encode fnc.
                     );

/* encode with a custom base */
String encoded = mybase.encode(byte[]);

/* directly decode with a custom base */
byte[] decoded = mybase.decode(encoded);

/* get decoder initialized with a custom base */
var decoder = MultibaseDecorer.getInstance(mybase, ...);

Installation

Maven

<dependency>
    <groupId>com.apicatalog</groupId>
    <artifactId>copper-multibase</artifactId>
    <version>0.5.0</version>
</dependency>

Gradle

Adnrod API level >= 26

implementation("com.apicatalog:copper-multibase:0.5.0")

Documentation

javadoc

Contributing

All PR's welcome!

Building

Fork and clone the project repository.

> cd copper-multibase
> mvn clean package

Resources

copper-multibase's People

Contributors

dependabot[bot] avatar filip26 avatar vorburger avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

vorburger

copper-multibase's Issues

Implement Base96CZ

just for fun: should use all 42 Czech letters * 2 + 10 numbers + two other characters

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.