Luhnov Algoritam
Luhnov Algoritam
Luhnov Algoritam
Description
The check digit is computed as follows:
Multipliers 1 2 1 2 1 2 1 2 1 2
= = = = = = = = = =
7 18 9 4 7 6 9 16 7 2
9 7
Sum digits 7 9 4 7 6 9 7 2
(1+8) (1+6)
).
Pseudocode implementation
The following function takes a card
number, including the check digit, as an
array of integers and outputs true if the
check digit is correct, false otherwise.
function
isValid(cardNumber[1..leng
th])
sum := 0
parity := length mod 2
for i from 1 to length
do
if i mod 2 !=
parity then
sum := sum +
cardNumber[i]
elseif
cardNumber[i] > 4 then
sum := sum + 2
* cardNumber[i] - 9
else
sum := sum + 2
* cardNumber[i]
end if
end for
return 10 - (sum mod
10)
end function
References
1. US patent 2950048A (https://worldwi
de.espacenet.com/textdoc?DB=EPO
DOC&IDX=US2950048A) , Luhn,
Hans P., "Computer for verifying
numbers", published 1960-08-23
2. "Annex B: Luhn formula for
computing modulus-10 "double-add-
double" check digits". Identification
cards — Identification of issuers —
Part 1: Numbering system (https://w
ww.iso.org/standard/70484.html)
(Standard). International
Organization for Standardization,
International Electrotechnical
Commission. January 2017. ISO/IEC
7812-1:2017.
External links
Implementation in 150 languages on
the Rosetta Code project (https://roset
tacode.org/wiki/Luhn_test_of_credit_c
ard_numbers)
Retrieved from
"https://en.wikipedia.org/w/index.php?
title=Luhn_algorithm&oldid=1160095853"