-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
3,099 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Build | ||
[Dd]ebug/ | ||
[Rr]elease/ | ||
[Oo]bj/ | ||
[Bb]in/ | ||
|
||
# VS | ||
*.suo | ||
|
||
# NuGet | ||
!.nuget/bin |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Full details can be found on the project page here: | ||
|
||
https://github.com/wallf/BaseNEncodings.Net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@echo off | ||
copy setting.nuspec ..\BaseNEncodings\BaseNEncodings.nuspec /y > nul | ||
bin\NuGet.exe pack ..\BaseNEncodings\BaseNEncodings.csproj -BasePath .\ -Prop Configuration=Release | ||
del ..\BaseNEncodings\BaseNEncodings.nuspec > nul | ||
echo. | ||
pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0"?> | ||
<package > | ||
<metadata> | ||
<id>WallF.BaseNEncodings</id> | ||
<version>$version$</version> | ||
<title>BaseNEncodings.Net</title> | ||
<description>$description$</description> | ||
<authors>wallf(wall.f.workshop#gmail.com)</authors> | ||
<copyright>$copyright$</copyright> | ||
<tags>Base16 Base32 Base64 Base-N RFC4648</tags> | ||
<projectUrl>https://github.com/wallf/BaseNEncodings.Net</projectUrl> | ||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<releaseNotes>Initial release.</releaseNotes> | ||
</metadata> | ||
<files> | ||
<file src="\..\RFC 4648.txt" target="RFC4648.txt"/> | ||
<file src="\content\readme.txt" target="readme.txt"/> | ||
</files> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BaseNEncodings", "BaseNEncodings\BaseNEncodings.csproj", "{1302C384-3DFD-4384-9485-F1707D6EC0FD}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple", "Simple\Simple.csproj", "{B96F5E5D-F9A5-468A-89B1-FD8E8A3DB421}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "Benchmark\Benchmark.csproj", "{2252E256-7062-4E2B-8DEE-DE63023E49C6}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1302C384-3DFD-4384-9485-F1707D6EC0FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1302C384-3DFD-4384-9485-F1707D6EC0FD}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1302C384-3DFD-4384-9485-F1707D6EC0FD}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1302C384-3DFD-4384-9485-F1707D6EC0FD}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{B96F5E5D-F9A5-468A-89B1-FD8E8A3DB421}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B96F5E5D-F9A5-468A-89B1-FD8E8A3DB421}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B96F5E5D-F9A5-468A-89B1-FD8E8A3DB421}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B96F5E5D-F9A5-468A-89B1-FD8E8A3DB421}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{2252E256-7062-4E2B-8DEE-DE63023E49C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2252E256-7062-4E2B-8DEE-DE63023E49C6}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2252E256-7062-4E2B-8DEE-DE63023E49C6}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2252E256-7062-4E2B-8DEE-DE63023E49C6}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System; | ||
using WallF.BaseNEncodings.Util; | ||
|
||
namespace WallF.BaseNEncodings | ||
{ | ||
/// <summary> | ||
/// Represents a Base16 encoding | ||
/// <para>Default constructor will create a standard Base16 encoding(RFC 4648)</para> | ||
/// </summary> | ||
public partial class Base16Encoding : BaseEncoding | ||
{ | ||
/// <summary> | ||
/// Standard Alphabet. | ||
/// </summary> | ||
public const string STANDARD_ALPHABET = "0123456789ABCDEF"; | ||
/// <summary> | ||
/// Default Encoding Name. | ||
/// </summary> | ||
public const string DEFAULT_NAME = "Standard Base16 Encoding"; | ||
|
||
private readonly char[] alphabet; | ||
private readonly string encodingName; | ||
|
||
/// <summary> | ||
/// Initializes a new instance that is a standard Base16 encoding(<a href="http://tools.ietf.org/rfc/rfc4648.txt">RFC 4648</a>) | ||
/// </summary> | ||
public Base16Encoding() : this(STANDARD_ALPHABET.ToCharArray(), DEFAULT_NAME, false) { } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the Base16Encoding class. Parameters specify the alphabet of encoding. | ||
/// </summary> | ||
/// <param name="alphabet">Alphabet for current encoding.</param> | ||
/// <exception cref="ArgumentNullException">alphabet is null</exception> | ||
/// <exception cref="ArgumentOutOfRangeException">size of alphabet is not 16</exception> | ||
/// <exception cref="ArgumentException">alphabet contains duplicated items</exception> | ||
public Base16Encoding(char[] alphabet) : this(alphabet, "Customized Base16 Encoding", true) { } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the Base16Encoding class. Parameters specify the alphabet and the name of encoding. | ||
/// </summary> | ||
/// <param name="alphabet">Alphabet for current encoding.</param> | ||
/// <param name="encodingName">Name for current encoding.</param> | ||
/// /// <exception cref="ArgumentNullException">alphabet or encoodingName is null</exception> | ||
/// <exception cref="ArgumentOutOfRangeException">size of alphabet is not 16</exception> | ||
/// <exception cref="ArgumentException">alphabet contains duplicated items</exception> | ||
public Base16Encoding(char[] alphabet, string encodingName) : this(alphabet, encodingName, true) { } | ||
|
||
internal Base16Encoding(char[] alphabet, string encodingName, bool verify) | ||
{ | ||
if (verify) | ||
{ | ||
if (alphabet == null) | ||
throw new ArgumentNullException("alphabet", "alphabet is null"); | ||
if (encodingName == null) | ||
throw new ArgumentNullException("encodingName", "encodingName is null"); | ||
if (alphabet.Length != 16) | ||
throw new ArgumentOutOfRangeException("alphabet", "size of alphabet is not 16"); | ||
if (ArrayFunctions.IsArrayDuplicate(alphabet)) | ||
throw new ArgumentException("alphabet", "alphabet contains duplicated items"); | ||
} | ||
this.alphabet = (char[])alphabet.Clone(); | ||
this.encodingName = encodingName; | ||
this.InitAlgorithm(this.alphabet); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the human-readable description of the current encoding. | ||
/// </summary> | ||
public override string EncodingName | ||
{ | ||
get { return encodingName; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets the being used alphabet of the current encoding. | ||
/// </summary> | ||
public override char[] Alphabet | ||
{ | ||
get { return (char[])alphabet.Clone(); } | ||
} | ||
|
||
/// <summary> | ||
/// Return value is always false, because of padding is not required for Base16 Encoding. | ||
/// </summary> | ||
public override bool IsPaddingRequired | ||
{ | ||
get { return false; } | ||
} | ||
|
||
/// <summary> | ||
/// Return value is always default character, because of padding is not required for Base16 Encoding. | ||
/// </summary> | ||
public override char PaddingCharacter | ||
{ | ||
get { return default(char); } | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using WallF.BaseNEncodings.Inner; | ||
|
||
namespace WallF.BaseNEncodings | ||
{ | ||
public partial class Base16Encoding : BaseEncoding | ||
{ | ||
private Base16 b; | ||
|
||
private void InitAlgorithm(char[] alphabet) | ||
{ | ||
this.b = new Base16(alphabet); | ||
} | ||
|
||
/// <summary> | ||
/// See <see cref="BaseEncoding.GetEncodeCountWithoutArgumentsValidation(int)"/>. | ||
/// </summary> | ||
protected override int GetEncodeCountWithoutArgumentsValidation(int length) | ||
{ | ||
return b.EncodeSize(length); | ||
} | ||
|
||
/// <summary> | ||
/// See <see cref="BaseEncoding.EncodeWithoutArgumentsValidation(byte[], int, int)"/>. | ||
/// </summary> | ||
protected override char[] EncodeWithoutArgumentsValidation(byte[] bytes, int offset, int length) | ||
{ | ||
char[] r = new char[b.EncodeSize(length)]; | ||
b.Encode(bytes, offset, length, r, 0, r.Length); | ||
return r; | ||
} | ||
|
||
/// <summary> | ||
/// See <see cref="BaseEncoding.EncodeWithoutArgumentsValidation(byte[], int, int, char[], int)"/>. | ||
/// </summary> | ||
/// <exception cref="ArgumentException">output sequence does not have enough capacity</exception> | ||
protected override int EncodeWithoutArgumentsValidation(byte[] bytesIn, int offsetIn, int lengthIn, char[] charsOut, int offsetOut) | ||
{ | ||
return b.Encode(bytesIn, offsetIn, lengthIn, charsOut, offsetOut); | ||
} | ||
|
||
/// <summary> | ||
/// See <see cref="BaseEncoding.GetDecodeCountWithoutArgumentsValidation(char[], int, int)"/>. | ||
/// </summary> | ||
/// <exception cref="FormatException">input sequence is not a valid base sequence</exception> | ||
protected override int GetDecodeCountWithoutArgumentsValidation(char[] chars, int offset, int length) | ||
{ | ||
return b.DecodeSize(length); | ||
} | ||
|
||
/// <summary> | ||
/// See <see cref="BaseEncoding.DecodeWithoutArgumentsValidation(char[], int, int)"/>. | ||
/// </summary> | ||
/// <exception cref="FormatException">input sequence is not a valid base sequence</exception> | ||
protected override byte[] DecodeWithoutArgumentsValidation(char[] chars, int offset, int length) | ||
{ | ||
byte[] r = new byte[b.DecodeSize(length)]; | ||
b.Decode(chars, offset, length, r, 0, r.Length); | ||
return r; | ||
} | ||
|
||
/// <summary> | ||
/// See <see cref="BaseEncoding.DecodeWithoutArgumentsValidation(char[], int, int, byte[], int)"/>. | ||
/// </summary> | ||
/// <exception cref="FormatException">input sequence is not a valid base sequence</exception> | ||
/// <exception cref="ArgumentException">output sequence does not have enough capacity</exception> | ||
protected override int DecodeWithoutArgumentsValidation(char[] charsIn, int offsetIn, int lengthIn, byte[] bytesOut, int offsetOut) | ||
{ | ||
return b.Decode(charsIn, offsetIn, lengthIn, bytesOut, offsetOut); | ||
} | ||
|
||
/// <summary> | ||
/// See <see cref="BaseEncoding.IsValidBaseSequenceWithoutArgumentsValidation(char[], int, int)"/>. | ||
/// </summary> | ||
protected override bool IsValidBaseSequenceWithoutArgumentsValidation(char[] chars, int offset, int length) | ||
{ | ||
return b.IsValidBaseSequence(chars, offset, length); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using System; | ||
using WallF.BaseNEncodings.Util; | ||
|
||
namespace WallF.BaseNEncodings | ||
{ | ||
/// <summary> | ||
/// Represents a Base32 encoding | ||
/// <para>Default constructor will create a standard Base32 encoding(RFC 4648)</para> | ||
/// </summary> | ||
public partial class Base32Encoding : BaseEncoding | ||
{ | ||
/// <summary> | ||
/// Standard Alphabet. | ||
/// </summary> | ||
public const string STANDARD_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; | ||
/// <summary> | ||
/// Standard Padding. | ||
/// </summary> | ||
public const char STANDARD_PADDING = '='; | ||
/// <summary> | ||
/// Default Encoding Name. | ||
/// </summary> | ||
public const string DEFAULT_NAME = "Standard Base32 Encoding"; | ||
|
||
private readonly char[] alphabet; | ||
private readonly char padding; | ||
private readonly string encodingName; | ||
|
||
/// <summary> | ||
/// Initializes a new instance that is a standard Base32 encoding(<a href="http://tools.ietf.org/rfc/rfc4648.txt">RFC 4648</a>) | ||
/// </summary> | ||
public Base32Encoding() : this(STANDARD_ALPHABET.ToCharArray(), STANDARD_PADDING, DEFAULT_NAME, false) { } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the Base32Encoding class. Parameters specify the alphabet and the padding character of encoding. | ||
/// </summary> | ||
/// <param name="alphabet">Alphabet for current encoding.</param> | ||
/// <param name="padding">Padding character for current encoding.</param> | ||
/// <exception cref="ArgumentNullException">alphabet is null</exception> | ||
/// <exception cref="ArgumentOutOfRangeException">size of alphabet is not 32</exception> | ||
/// <exception cref="ArgumentException">alphabet contains duplicated items</exception> | ||
public Base32Encoding(char[] alphabet, char padding) : this(alphabet, padding, "Customized Base32 Encoding", true) { } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the Base16Encoding class. Parameters specify the alphabet and the padding character and the name of encoding. | ||
/// </summary> | ||
/// <param name="alphabet">Alphabet for current encoding.</param> | ||
/// <param name="padding">Padding character for current encoding.</param> | ||
/// <param name="encodingName">Name for current encoding.</param> | ||
/// /// <exception cref="ArgumentNullException">alphabet or encoodingName is null</exception> | ||
/// <exception cref="ArgumentOutOfRangeException">size of alphabet is not 32</exception> | ||
/// <exception cref="ArgumentException">alphabet contains duplicated items, or padding already existed in alphabet</exception> | ||
public Base32Encoding(char[] alphabet, char padding, string encodingName) : this(alphabet, padding, encodingName, true) { } | ||
|
||
internal Base32Encoding(char[] alphabet, char padding, string encodingName, bool verify) | ||
{ | ||
if (verify) | ||
{ | ||
if (alphabet == null) | ||
throw new ArgumentNullException("alphabet", "alphabet is null"); | ||
if (encodingName == null) | ||
throw new ArgumentNullException("encodingName", "encodingName is null"); | ||
if (alphabet.Length != 32) | ||
throw new ArgumentOutOfRangeException("alphabet", "size of alphabet is not 32"); | ||
if (ArrayFunctions.IsArrayDuplicate(alphabet)) | ||
throw new ArgumentException("alphabet", "alphabet contains duplicated items"); | ||
if (ArrayFunctions.IsArrayContains(alphabet, padding)) | ||
throw new ArgumentException("padding", "padding already existed in alphabet"); | ||
} | ||
this.alphabet = (char[])alphabet.Clone(); | ||
this.padding = padding; | ||
this.encodingName = encodingName; | ||
this.InitAlgorithm(this.alphabet, this.padding); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the human-readable description of the current encoding. | ||
/// </summary> | ||
public override string EncodingName | ||
{ | ||
get { return encodingName; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets the being used alphabet of the current encoding. | ||
/// </summary> | ||
public override char[] Alphabet | ||
{ | ||
get { return (char[])alphabet.Clone(); } | ||
} | ||
|
||
/// <summary> | ||
/// Return values is always true for the Base32 Encoding. | ||
/// </summary> | ||
public override bool IsPaddingRequired | ||
{ | ||
get { return true; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets the being used padding character of the current encoding. | ||
/// </summary> | ||
public override char PaddingCharacter | ||
{ | ||
get { return padding; } | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.