12,444,430 members (50,214 online)
alternative version

40.4K views
12 bookmarked
Posted

# Luhn' s Algorithm

, 8 Dec 2004
 Rate this:
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.

A list of licenses authors might use can be found here

## Share

 Austria
No Biography provided

## You may also be interested in...

 Pro Pro

 First Prev Next
 Actually, this method only needs one line changed to compute the correct Luhn check-digit (the "return" equation is wrong) kirkaiya6-Aug-09 18:42 kirkaiya 6-Aug-09 18:42
 Incorrect Algorithm? Peebles3-Mar-05 2:36 Peebles 3-Mar-05 2:36
 use this code... Joel Thoms18-Jan-05 11:47 Joel Thoms 18-Jan-05 11:47
 how to use Joel Thoms18-Jan-05 11:41 Joel Thoms 18-Jan-05 11:41
 A section on how to use would be nice. I input 2 different valid credit card numbers and received values 3 and 9. When an invalid credit card number was input, I received a 4. I think there may be something wrong in the algorythm, I cannot use this. Joel Thoms http://joel.net
 wrote an implementation myslef some time ago