Click here to Skip to main content
11,486,649 members (73,638 online)
Click here to Skip to main content

Luhn' s Algorithm

, 8 Dec 2004 38K 795 13
Rate this:
Please Sign up or sign in to vote.
Calculating checksum number using Luhn's algorithm

Introduction

This sample implements the functionality of generating checksum number using Luhn's algorithm.

I've created a class LuhnAlgorithm with a static function:

public static int GetLuhnAlgorithmNumber(string data);

Return value is the generated number.

Definition

The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm, was developed in the 1960s as a method of validating identification numbers. It is a simple checksum formula used to validate a variety of account numbers, such as credit card numbers and Canadian Social Insurance Numbers. Much of its notoriety comes from credit card companies' adoption of it shortly after its creation in the late 1960s by IBM scientist Hans Peter Luhn (1896–1964).

Explanation of the Luhn's algorithm can be found here.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

wapnethr

Austria Austria
No Biography provided

Comments and Discussions

 
GeneralActually, this method only needs one line changed to compute the correct Luhn check-digit (the "return" equation is wrong) Pin
kirkaiya6-Aug-09 19:42
memberkirkaiya6-Aug-09 19:42 
QuestionIncorrect Algorithm? Pin
Peebles3-Mar-05 3:36
memberPeebles3-Mar-05 3:36 
Generaluse this code... Pin
Joel Thoms18-Jan-05 12:47
memberJoel Thoms18-Jan-05 12:47 
Questionhow to use Pin
Joel Thoms18-Jan-05 12:41
memberJoel Thoms18-Jan-05 12:41 
Generalwrote an implementation myslef some time ago Pin
<div style='color:#6699cc; '>MadHatter ¢</div>9-Dec-04 8:02
member
MadHatter ¢
9-Dec-04 8:02 
GeneralExplaining my vote Pin
Jason De Arte8-Dec-04 9:45
memberJason De Arte8-Dec-04 9:45 
Yes, I rated this article low. But I think it's important to write _why_ I rated it low for the benefit of the author. This is NOT meant to be taken as an attack - but I must admit I haven't had any caffeine yet this morning and I may still be a bit cranky.
1) The article is terse and leaves me wondering why I would need to reference this code in the future. Maybe an example of _why_ this code is cool and for what it can be used for?
2) the "Definition" is a copy and paste of the "Explanation" that you link to.
3) You only provide a zipped source file whose source appears to have the same byte count as your article. Maybe if you had a sample? or highlighted some bits of the code in the article?
4) The list of compatible platforms is HUGE, I had no idea that a C# source file would work on PalmOS. Wink | ;)

It's a nice first start for an article, but you should read "What is a good article" http://www.codeproject.com/scrapbook/whatisagoodarticle.asp[^]

And maybe a few of the top ranked articles for their structure
http://www.codeproject.com/script/articles/top_articles.asp?st=2[^]

[ Jason De Arte | Toy Maker | 1001010.com ]

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 8 Dec 2004
Article Copyright 2004 by wapnethr
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid