{"id":20057402,"url":"https://github.com/shinji-san/luhndotnet","last_synced_at":"2025-05-05T14:31:09.938Z","repository":{"id":65375480,"uuid":"499670383","full_name":"shinji-san/LuhnDotNet","owner":"shinji-san","description":"An C# implementation of the Luhn algorithm","archived":false,"fork":false,"pushed_at":"2025-03-17T12:46:03.000Z","size":2038,"stargazers_count":2,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T00:22:51.046Z","etag":null,"topics":["charp","check-digit-formula","dotnet","luhn","luhn-algorithm","mod-10-algorithm","modulus-10-algorithm"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shinji-san.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-03T22:44:26.000Z","updated_at":"2024-12-28T22:35:22.000Z","dependencies_parsed_at":"2024-02-19T20:33:27.406Z","dependency_job_id":"0677dc4b-fa8a-49fa-a5f9-01f83b14ce2e","html_url":"https://github.com/shinji-san/LuhnDotNet","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinji-san%2FLuhnDotNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinji-san%2FLuhnDotNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinji-san%2FLuhnDotNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinji-san%2FLuhnDotNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shinji-san","download_url":"https://codeload.github.com/shinji-san/LuhnDotNet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252514891,"owners_count":21760456,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["charp","check-digit-formula","dotnet","luhn","luhn-algorithm","mod-10-algorithm","modulus-10-algorithm"],"created_at":"2024-11-13T12:58:53.822Z","updated_at":"2025-05-05T14:31:09.930Z","avatar_url":"https://github.com/shinji-san.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LuhnDotNet\r\n![LuhnDotNet Logo](images/social-media-preview.png)\r\n\r\nA C# implementation of the Luhn algorithm.\r\n\r\nThe Luhn algorithm is a checksum formula used to validate identification numbers like credit card numbers. It works by doubling every second digit from the right, summing all the digits, and checking if the total is a multiple of 10. It's widely used and is specified in ISO/IEC 7812-1.\r\n\r\n# Build \u0026 Test Status Of Default Branch\r\n\u003ctable\u003e\r\n  \u003cthead\u003e\r\n    \u003ctr\u003e\r\n        \u003cth\u003eStatus\u003c/th\u003e\r\n        \u003cth\u003eSolution\u003c/th\u003e\r\n        \u003cth\u003eProject Format\u003c/th\u003e\r\n        \u003cth\u003e.NET Version\u003c/th\u003e\r\n    \u003c/tr\u003e\r\n  \u003c/thead\u003e\r\n  \u003ctbody\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd rowspan=9\u003e\u003ca href =\"https://github.com/shinji-san/LuhnDotNet/actions/workflows/dotnetall.yml\" target=\"_blank\"\u003e\u003cimg src=\"https://github.com/shinji-san/LuhnDotNet/actions/workflows/dotnetall.yml/badge.svg?branch=main\" alt=\"Build status\"/\u003e\u003c/a\u003e\u003c/td\u003e\r\n          \u003ctd rowspan=9\u003e\u003ccode\u003eLuhnDotNet.sln\u003c/code\u003e\u003c/td\u003e\r\n          \u003ctd rowspan=9\u003eSDK\u003c/td\u003e\r\n          \u003ctd\u003eStandard 2.0\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eStandard 2.1\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eFX 4.6.2\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eFX 4.7\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eFX 4.7.1\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eFX 4.7.2\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eFX 4.8\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003e.NET 8\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003e.NET 9\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n  \u003c/tbody\u003e\r\n\u003c/table\u003e\r\n\r\n# NuGet\r\n## Supported Target Frameworks\r\n\u003ctable\u003e\r\n  \u003cthead\u003e\r\n    \u003ctr\u003e\r\n        \u003cth\u003eBuild And Test Status\u003c/th\u003e\r\n        \u003cth\u003eNuGet Version\u003c/th\u003e\r\n        \u003cth\u003eGit Tag\u003c/th\u003e\r\n        \u003cth\u003eTarget Frameworks\u003c/th\u003e\r\n    \u003c/tr\u003e\r\n  \u003c/thead\u003e\r\n  \u003ctbody\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd rowspan=9\u003e\u003ca href=\"https://github.com/shinji-san/LuhnDotNet/actions/workflows/publishing.yml\" target=\"_blank\"\u003e\u003cimg src=\"https://github.com/shinji-san/LuhnDotNet/actions/workflows/publishing.yml/badge.svg\" alt=\"LuhnDotNet - NuGet Publishing\"/\u003e\u003c/a\u003e\u003c/td\u003e\r\n          \u003ctd rowspan=9\u003e\u003ca href=\"https://badge.fury.io/nu/LuhnDotNet\" target=\"_blank\"\u003e\u003cimg src=\"https://badge.fury.io/nu/LuhnDotNet.svg\" alt=\"NuGet Version 1.3.0\"/\u003e\u003c/a\u003e\u003c/td\u003e\r\n          \u003ctd rowspan=9\u003e\u003ca href=\"https://github.com/shinji-san/LuhnDotNet/tree/v1.3.0\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/LuhnDotNet-1.3.0-green.svg?logo=github\u0026logoColor=959da5\u0026color=2ebb4e\u0026labelColor=2b3137\" alt=\"Tag\"/\u003e\u003c/a\u003e\u003c/td\u003e\r\n          \u003ctd\u003e.NET 8\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003e.NET 9\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eStandard 2.0\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eStandard 2.1\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eFX 4.6.2\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eFX 4.7\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eFX 4.7.1\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eFX 4.7.2\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n      \u003ctr\u003e\r\n          \u003ctd\u003eFX 4.8\u003c/td\u003e\r\n      \u003c/tr\u003e\r\n  \u003c/tbody\u003e\r\n\u003c/table\u003e\r\n\r\n## Install LuhnDotNet package\r\n\r\n1. Open a console and switch to the directory, containing your project file.\r\n\r\n2. Use the following command to install version 1.3.0 of the LuhnDotNet package:\r\n\r\n    ```dotnetcli\r\n    dotnet add package LuhnDotNet -v 1.3.0 -f \u003cFRAMEWORK\u003e\r\n    ```\r\n\r\n3. After the completion of the command, look at the project file to make sure that the package is successfully installed.\r\n\r\n   You can open the `.csproj` file to see the added package reference:\r\n\r\n    ```xml\r\n    \u003cItemGroup\u003e\r\n      \u003cPackageReference Include=\"LuhnDotNet\" Version=\"1.3.0\" /\u003e\r\n    \u003c/ItemGroup\u003e\r\n    ```\r\n## Remove LuhnDotNet package\r\n\r\n1. Open a console and switch to the directory, containing your project file.\r\n\r\n2. Use the following command to remove the LuhnDotNet package:\r\n\r\n    ```dotnetcli\r\n    dotnet remove package LuhnDotNet\r\n    ```\r\n\r\n3. After the completion of the command, look at the project file to make sure that the package is successfuly removed.\r\n\r\n   You can open the `.csproj` file to check the deleted package reference.\r\n\r\n# API Documentation\r\nYou can find the API documentation [here](https://sebastian-walther.de/LuhnDotNet/api/LuhnDotNet.html).\r\n\r\n# Usage\r\n## Compute the Luhn check digit\r\n```csharp\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing LuhnDotNet;\r\n\r\nnamespace Example1\r\n{\r\n    public class Program\r\n    {\r\n        public static void Main(string[] args)\r\n        {\r\n            var checkDigit = \"37828224631000\".ComputeLuhnCheckDigit();\r\n            //// Must be 5\r\n            Console.WriteLine(checkDigit);\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n## Compute the Luhn number\r\n```csharp\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing LuhnDotNet;\r\n\r\nnamespace Example2\r\n{\r\n    public class Program\r\n    {\r\n        public static void Main(string[] args)\r\n        {\r\n            var luhnNumber = \"37828224631000\".ComputeLuhnNumber();\r\n            //// Must be 378282246310005\r\n            Console.WriteLine(luhnNumber);\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n## Validate Luhn number\r\n```csharp\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing LuhnDotNet;\r\n\r\nnamespace Example3\r\n{\r\n    public class Program\r\n    {\r\n        public static void Main(string[] args)\r\n        {\r\n            var isValid = \"378282246310005\".IsValidLuhnNumber();\r\n            //// Must be 'true'\r\n            Console.WriteLine(isValid);\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n## Validate number and corresponding Luhn check digit\r\n```csharp\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing LuhnDotNet;\r\n\r\nnamespace Example4\r\n{\r\n    public class Program\r\n    {\r\n        public static void Main(string[] args)\r\n        {\r\n            byte checkDigit = 5;\r\n            var isValid = checkDigit.IsValidLuhnCheckDigit(\"37828224631000\");\r\n            //// Must be 'true'\r\n            Console.WriteLine(isValid);\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n## Validate ISIN with LuhnDotNet and ConvertAlphaNumericToNumeric\r\n\r\nThe `LuhnDotNet` library can be used in combination with the `ConvertAlphaNumericToNumeric` method to validate an International Securities Identification Number (ISIN). An ISIN uniquely identifies a security, such as stocks, bonds or derivatives. It is a 12-character alphanumeric code.\r\n\r\nThe `ConvertAlphaNumericToNumeric` method is used to convert the alphanumeric ISIN to a numeric string, where each letter in the input string is replaced by its decimal ASCII value minus 55. This numeric string can then be validated using the `Luhn.IsValid` method.\r\n\r\nHere is an example of how to use these methods to validate an ISIN:\r\n\r\n```csharp\r\nusing System;\r\nusing LuhnDotNet;\r\n\r\nnamespace Example5\r\n{\r\n    public class Program\r\n    {\r\n        public static void Main(string[] args)\r\n        {\r\n            string isin = \"US0378331005\";\r\n            bool isValid = isin.ConvertAlphaNumericToNumeric().IsValidLuhnNumber();\r\n            Console.WriteLine($\"The ISIN {isin} is valid: {isValid}\");\r\n        }\r\n    }\r\n}\r\n```\r\n## Compute ISIN Check Digit with LuhnDotNet and ConvertAlphaNumericToNumeric\r\n\r\nThe `LuhnDotNet` library provides the `ComputeLuhnCheckDigit` method which can be used to compute the check digit of a numeric string according to the Luhn algorithm. When dealing with an International Securities Identification Number (ISIN), which is a 12-character alphanumeric code, we first need to convert the alphanumeric ISIN to a numeric string. This can be achieved using the `ConvertAlphaNumericToNumeric` method.\r\n\r\nHere is an example of how to compute the check digit of an ISIN:\r\n\r\n```csharp\r\nusing System;\r\nusing LuhnDotNet;\r\n\r\nnamespace Example6\r\n{\r\n    public class Program\r\n    {\r\n        public static void Main(string[] args)\r\n        {\r\n            string isinWithoutCheckDigit = \"US037833100\";\r\n            byte checkDigit = isinWithoutCheckDigit.ConvertAlphaNumericToNumeric().ComputeLuhnCheckDigit();\r\n            Console.WriteLine($\"The check digit for ISIN {isinWithoutCheckDigit} is: {checkDigit}\");\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n## Compute credit card number with LuhnDotNet\r\nThe `LuhnDotNet` library can be used to compute the check digit of a credit card number. The check digit is the last digit of the credit card number, which is used to validate the number according to the Luhn algorithm.\r\n\r\n```csharp\r\nusing System;\r\nusing LuhnDotNet;\r\n\r\nnamespace Example7\r\n{\r\n    public class Program\r\n    {\r\n        public static void Main(string[] args)\r\n        {\r\n            string creditCardNumberWithoutCheckDigit = \"4417 1234 5678 911\".Replace(\" \", \"\");\r\n            byte checkDigit = creditCardNumberWithoutCheckDigit.ComputeLuhnCheckDigit();\r\n            Console.WriteLine($\"The check digit for credit card number {creditCardNumberWithoutCheckDigit} is: {checkDigit}\");\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n## Validate credit card number with LuhnDotNet\r\nThe `LuhnDotNet` library can be used to validate a credit card number according to the Luhn algorithm. The `IsValid` method returns `true` if the credit card number is valid, and `false` otherwise.\r\n\r\n```csharp\r\nusing System;\r\nusing LuhnDotNet;\r\n\r\nnamespace Example8\r\n{\r\n    public class Program\r\n    {\r\n        public static void Main(string[] args)\r\n        {\r\n            string creditCardNumber = \"4417 1234 5678 9113\".Replace(\" \", \"\");\r\n            bool isValid = creditCardNumber.IsValidLuhnNumber();\r\n            Console.WriteLine($\"The credit card number {creditCardNumber} is valid: {isValid}\");\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n# CLI building instructions\r\nFor the following instructions, please make sure that you are connected to the internet. If necessary, NuGet will try to restore the [xUnit](https://xunit.net/) packages.\r\n## Using dotnet to build for .NET 8, .NET 9 and .NET FX 4.x\r\nUse one of the following solutions with `dotnet` to build [LuhnDotNet](#luhndotnet):\r\n* `LuhnDotNet.sln` (all, [see table](#build--test-status-of-default-branch))\r\n\r\n\r\nThe syntax is:\r\n```dotnetcli\r\ndotnet {restore|build|test} -c {Debug|Release} LuhnDotNet.sln\r\n```\r\n\r\n### Restore NuGet packages\r\n\r\n```dotnetcli\r\ndotnet restore LuhnDotNet.sln\r\n```\r\n\r\nThe instructions below are examples, which operate on the `LuhnDotNet.sln`.\r\n### Build Debug configuration\r\n\r\n```dotnetcli\r\ndotnet build -c Debug --no-restore LuhnDotNet.sln\r\n```\r\n\r\n### Build Release configuration\r\n\r\n```dotnetcli\r\ndotnet build -c Release --no-restore LuhnDotNet.sln\r\n```\r\n\r\n### Test Debug configuration\r\n\r\n```dotnetcli\r\ndotnet test -c Debug --no-restore --no-build LuhnDotNet.sln\r\n```\r\n\r\n### Test Release configuration\r\n\r\n```dotnetcli\r\ndotnet test -c Release --no-restore --no-build LuhnDotNet.sln\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinji-san%2Fluhndotnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshinji-san%2Fluhndotnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinji-san%2Fluhndotnet/lists"}