quickford 1.1.0

Crockford Base32 encoding for 64-bit identifiers. In comparison to other, similar libraries, quickford focuses on speed and efficiency. Have fun saving electricity!

Install-Package quickford -Version 1.1.0
dotnet add package quickford --version 1.1.0
<PackageReference Include="quickford" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add quickford --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

quickford

Base32 encoding for 64-bit values.

Crockford Base32 Encoding is most commonly used to make numeric identifiers slightly more user-resistant. Similar to Hashids, the purpose here is to make the identifiers shorter and less confusing. Unlike Hashids, Crockford Base32 does nothing to conceal the real value of the number (beyond the actual encoding, anyway) and the fact that they are sequential is still pretty obvious when you see consecutive identifiers side by side.

This library does not support encoding and decoding of arbitrary data. Additionally, the spec supports the idea of check digits, but this library currently does not.

The primary purpose of this library is to provide high performance, user-resistant encoding of numeric identifiers. To that end, both encoding and decoding are, in fact, pretty darn fast--an average of eight times faster than the most popular alternative on nuget.org. Additionally, no initialization is required; all methods are static. (And I mean static. There is no lazy initialization nonsense here!)

This library is a port of crockford for Rust.

Usage

Encoding

Encoding is a one-step process.

var x = Base32.Encode(5111);
Assert.Equal("4ZQ", x);

If you want lowercase, then... Well, tough. However, we do now support encoding to a buffer of your choice rather than a new one created in the function. Read on to learn about plan B...

Alternate encoding

var buffer = new StringBuilder();
Base32.Encode(5111, buffer);
Assert.Equal("4ZQ", buffer.ToString());

...This will allow you to avoid additional allocations associated with creating a new stringbuilder on each call to Encode(). The call to ToString() is unavoidable.

Decoding

Decoding is a two-step process. This is because you can feed any string to the decoder, and the decoder will return an error if you try to convince it that &quot;Hello, world!&quot; is a number. (Hint: it isn't.)

var x = Base32.Decode("4zq");
var y = Base32.Decode("4ZQ");

Assert.Equal(5111, x.Value);
Assert.Equal(5111, y.Value);

So, step one is to call the decode function. Step two is to match/verify/unwrap/throw away the output.

License

Licensed under either of

  • Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

quickford

Base32 encoding for 64-bit values.

Crockford Base32 Encoding is most commonly used to make numeric identifiers slightly more user-resistant. Similar to Hashids, the purpose here is to make the identifiers shorter and less confusing. Unlike Hashids, Crockford Base32 does nothing to conceal the real value of the number (beyond the actual encoding, anyway) and the fact that they are sequential is still pretty obvious when you see consecutive identifiers side by side.

This library does not support encoding and decoding of arbitrary data. Additionally, the spec supports the idea of check digits, but this library currently does not.

The primary purpose of this library is to provide high performance, user-resistant encoding of numeric identifiers. To that end, both encoding and decoding are, in fact, pretty darn fast--an average of eight times faster than the most popular alternative on nuget.org. Additionally, no initialization is required; all methods are static. (And I mean static. There is no lazy initialization nonsense here!)

This library is a port of crockford for Rust.

Usage

Encoding

Encoding is a one-step process.

var x = Base32.Encode(5111);
Assert.Equal("4ZQ", x);

If you want lowercase, then... Well, tough. However, we do now support encoding to a buffer of your choice rather than a new one created in the function. Read on to learn about plan B...

Alternate encoding

var buffer = new StringBuilder();
Base32.Encode(5111, buffer);
Assert.Equal("4ZQ", buffer.ToString());

...This will allow you to avoid additional allocations associated with creating a new stringbuilder on each call to Encode(). The call to ToString() is unavoidable.

Decoding

Decoding is a two-step process. This is because you can feed any string to the decoder, and the decoder will return an error if you try to convince it that &quot;Hello, world!&quot; is a number. (Hint: it isn't.)

var x = Base32.Decode("4zq");
var y = Base32.Decode("4ZQ");

Assert.Equal(5111, x.Value);
Assert.Equal(5111, y.Value);

So, step one is to call the decode function. Step two is to match/verify/unwrap/throw away the output.

License

Licensed under either of

  • Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Release Notes

Add TryDecode method.

  • .NETStandard 2.0

    • No dependencies.

Version History

Version Downloads Last updated
1.1.0 233 5/18/2018
1.0.1 225 2/7/2018
1.0.0 176 2/7/2018
1.0.0-rc 259 1/8/2018