SlxLuhnLibrary 1.0.2

.NET Standard 2.0
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, C# scripting and .NET Interactive. 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


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) :
// 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 Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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

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 14,005 8/24/2018
1.0.1 836 4/16/2018
1.0.0 801 4/16/2018