JosephChris.BaseConvert 2.0.1

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package JosephChris.BaseConvert --version 2.0.1
NuGet\Install-Package JosephChris.BaseConvert -Version 2.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JosephChris.BaseConvert" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JosephChris.BaseConvert --version 2.0.1
#r "nuget: JosephChris.BaseConvert, 2.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JosephChris.BaseConvert as a Cake Addin
#addin nuget:?package=JosephChris.BaseConvert&version=2.0.1

// Install JosephChris.BaseConvert as a Cake Tool
#tool nuget:?package=JosephChris.BaseConvert&version=2.0.1

Base Converter

This is a simple base converter. It can encode and decode a number or bytes from/to base-x strings.

This project can be used for: binary encoding (Base32/16, which is ususally no API provided by system and framework), URL shorting, number shorting, etc.

Installation

Use Visual Studio NuGet Manager

Search JosephChris.BaseConvert in Visual Studio NuGet Manager and install.

Use CLI (Package Manager or .NET CLI)

# Package Manager
Install-Package JosephChris.BaseConvert -Version <version>

# .NET CLI
dotnet add package JosephChris.BaseConvert --version <version>

Use Project File Configuration

<PackageReference Include="JosephChris.BaseConvert" Version="<version>" />

Getting Started

This project is under JosephChris.BaseConvert namespace. At the start of the code file, please add code below:

using JosephChris.BaseConvert;
using JosephChris.BaseConvert.Exceptions;

Base64 Encode and Decode

var base64Converter = new BinaryConvert(); // Base64 is default
var base64Result = base64Converter.Encode(Encoding.UTF8.GetBytes("Test String"));
var base64DecodedString = Encoding.UTF8.GetString(base64Converter.Decode(base64Result));

Shortcuts

There are shortcuts to initialize a new instance of BinaryConvert and NumberConvert class. (Under namespace JosephChris.BaseConvert)

  • Common.Base64 for Binary to RFC 4648 Base64.
  • Common.Base32 for Binary to RFC 4648 Base32 (Non-Hex).
  • Common.Base16 for Binary to RFC 4648 Base16.
  • Common.Base36 for Number to Base36 (Upper Case, alphabet: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ).
  • Common.Base62 for Number to Base62 (Alphabet: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ).
  • Common.Base58 for Number to Base58 (Alphabet: 123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ).
  • Common.BitCoinBase58 for Number to Bitcoin Sthyle Base58 (Alphabet: 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz, see: Base58 - Wikipedia).
  • Common.JczBase35 for Joseph Chris's URL Shorter Base35.

Base Convert Number with Custom Alphabet

var converter = new NumberConvert("ASDF");
var result = converter.Encode(1);

Handling Errors

This project introduces 4 Exceptions, under JosephChris.BaseConvert.Exceptions namespace.

  • AlphabetLengthIsNotPowerOfTwoException: When initializing BinaryConvert, log2(Length of Alphabet) can not convert to an integer.
  • AlphabetNotUniqueException: There are duplicate characters in the alphater.
  • NumberNotPositiveException: Trying to encode a negative number. Only positive number is supported now.
  • PadCharacterInAlphabetException: When initializing BinaryConvert, the pad character is in the alphabet, which is not supported.

This project also throws a OverflowException when decoding an base-converted string to Int32 but the value exceeds the maximum of Int32.

API

See API.

Test Report

See TestReport folder.

Performance Notice

This project has low performance when encoding and decoding a binary more then 65535 bytes. It may cost more then 40 seconds. Please take this into consideration.

Changelog

Version 2.0.0

  • Change namespace to JosephChris.BaseConvert
  • Add binary convert future.
  • Support arbitrarily large integer in number convert.

Reporting Bugs

This project uses GitHub Issue to track bugs.

Contributing

Just fork and edit, then pull result.

Requirements: Write tests for your changes and run locally before pull result, coverage >= 99%, all passed.

License

Copyright ©2020 Joseph Chris

This project is the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated