Skip to content

A .NET library to encode data in Base-N (e.g. base32, base64). F# and C# friendly.

License

Notifications You must be signed in to change notification settings

gtbuchanan/BaseNcode

Repository files navigation

BaseNcode

CI

A .NET library to encode data in Base-N. F# and C# friendly.

Disclaimer

This library was created as an F# learning exercise. For a more performance-focused implementation, you may want to consider SimpleBase.

Supported Encodings

Usage

All encodings follow the same API pattern so you can extrapolate the following examples to any of the aforementioned encodings.

Import

// F#
open BaseNcode.FSharp
// C#
using BaseNcode;

F# Example

open System.Text

// Encode
let bytes = Encoding.UTF8.GetBytes("foobar")
let encodedString = Base32.encode true bytes
printfn encodedString // MZXW6YTBOI======

// Decode
let decodeErrorToString = function
  | InvalidChar ic -> sprintf "Invalid character %c at index %i" ic.Char ic.Index

match Base32.decode encodedString with
| Ok decodedBytes -> Encoding.UTF8.GetString(decodedBytes) |> printfn // foobar
| Error errors -> Seq.map decodeErrorToString errors |> printfn

C# Example

using System.Text;

// Encode
var bytes = Encoding.UTF8.GetBytes("foobar");
var encodedString = Base32.Encode(bytes);
Console.WriteLine(encodedString); // MZXW6YTBOI======

// Decode
var decodedBytes = Base32.Decode(encodedString);
Console.WriteLine(Encoding.UTF8.GetString(decodedBytes)); // foobar

About

A .NET library to encode data in Base-N (e.g. base32, base64). F# and C# friendly.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published