SlxLuhnLibrary 1.0.2

dotnet add package SlxLuhnLibrary --version 1.0.2                
NuGet\Install-Package SlxLuhnLibrary -Version 1.0.2                
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="SlxLuhnLibrary" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SlxLuhnLibrary --version 1.0.2                
#r "nuget: SlxLuhnLibrary, 1.0.2"                
#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 SlxLuhnLibrary as a Cake Addin
#addin nuget:?package=SlxLuhnLibrary&version=1.0.2

// Install SlxLuhnLibrary as a Cake Tool
#tool nuget:?package=SlxLuhnLibrary&version=1.0.2                

SlxLuhnLibrary

The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers in the United States, Canadian Social Insurance Numbers, Israel ID Numbers and Greek Social Security Numbers (ΑΜΚΑ). It was created by IBM scientist Hans Peter Luhn and described in U.S. Patent No. 2,950,048, filed on January 6, 1954, and granted on August 23, 1960.

Here I implement the Luhn mod N algorithm which is an extension to the Luhn algorithm (also known as mod 10 algorithm) that allows it to work with sequences of non-numeric characters. This can be useful when a check digit is required to validate an identification string composed of letters, a combination of letters and digits or even any arbitrary set of characters.

To test:

  1. Generate a new string with the luhn verification charater for a string (composed with modulo 10 caracters) :
ClsLuhnLibrary.WithLuhn_Base10("35823805800008"); 
// Returns "358238058000088"
  1. Generate the luhn verification charater for a string (composed with modulo 10 caracters) :
ClsLuhnLibrary.GenerateCheckCharacter("453908962903274", ClsLuhnLibrary.CharacterSet.Base10);
// Returns '4'
  1. Validate a composed with modulo 10 characters String :
ClsLuhnLibrary.ValidateCheckCharacter("4539089629032744", ClsLuhnLibrary.CharacterSet.Base10);
//  Returns true

Bonus Points You've got the same thing for built in Base36_0to9_atoz, Base62_0to9_atoz_AtoZ, and user set of characters

ClsLuhnLibrary.Init_BaseUser(new Char[] { '#', '!', '*' });
String str = "**##!!";
Char? cRc = ClsLuhnLibrary.GenerateCheckCharacter(str, ClsLuhnLibrary.CharacterSet.BaseUser);
Assert.AreEqual('*', cRc, $"The result of GenerateCheckCharacter for {str} is '*'");

2018-08-24 Patch the CheckLuhn_BaseUser

String strBaseUser = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Boolean blRc = ClsLuhnLibrary.CheckLuhn_BaseUser("A11993F", strBaseUser.ToCharArray());
Assert.AreEqual(blRc, true, $"The result of CheckLuhn_BaseUser for A11993L is OK");
blRc = ClsLuhnLibrary.CheckLuhn_BaseUser("A11993M", strBaseUser.ToCharArray());
Assert.AreEqual(blRc, false, $"The result of CheckLuhn_BaseUser for A11993L is OK");
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 (1)

Showing the top 1 NuGet packages that depend on SlxLuhnLibrary:

Package Downloads
Rangerus.RSAIDGen

Simple to use library for generating Random but valid south african id numbers

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 20,760 8/24/2018
1.0.1 1,012 4/16/2018
1.0.0 965 4/16/2018