10000 GitHub - greglook/alphabase: A simple Clojure(script) library to encode binary data in different bases using alphabets.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

A simple Clojure(script) library to encode binary data in different bases using alphabets.

License

Notifications You must be signed in to change notification settings

greglook/alphabase

Repository files navigation

alphabase

CircleCI codecov cljdoc

A simple cross-compiled Clojure(Script) library to handle encoding binary data in different bases using defined alphabets. If you've ever wanted a simple way to encode a byte array as a hexadecimal string, or base32, or other bases, this library is for you!

Installation

Library releases are published on Clojars. To use the latest version, add the following dependency to your project:

Clojars Project

Usage

  • alphabase.bytes namespace for generic byte-array handling
  • alphabase.radix for arbitrary alphabet support
  • Built-in support for octal, hexadecimal, base32, base58, and base64
=> (require '[alphabase.bytes :as b]
            '[alphabase.base16 :as hex])
            '[alphabase.base32 :as b32]
            '[alphabase.base58 :as b58]

=> (def data (b/random-bytes 32))

=> (hex/encode data)
"333A0FC9D17E07FF9A75AFCA02DF9AB32FDB9EB71565E810E981773BDD1E0C90"

=> (b/bytes= data (hex/decode *1))
true

=> (b32/encode data)
"MZ2B7E5C7QH76NHLL6KALPZVMZP3OPLOFLF5AIOTALXHPOR4DEQ"

=> (b/bytes= data (b32/decode *1))
true

;; base32 is case-insensitive
=> (b/bytes= data (b32/decode (clojure.string/lower-case *2)))
true

=> (b58/encode data)
"4Sy9GnemD6QbtaLtVTkZsZeZXExFmvGk7dJy1gDnBJCF"

=> (b/bytes= data (b58/decode *1))
true

Testing

The unit tests can be run using the following commands:

# Clojure tests
bin/test clj

# ClojureScript tests on Node
bin/test cljs

# Babashka tests
bin/test bb

For interactive development, start a REPL:

# Clojure REPL
bin/repl

License

This is free and unencumbered software released into the public domain. See the UNLICENSE file for more information.

About

A simple Clojure(script) library to encode binary data in different bases using alphabets.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  
0