This page allows you to examine the variables generated by the Edit Filter for an individual change.

Variables generated for this change

VariableValue
Edit count of the user (user_editcount)
0
Name of the user account (user_name)
'Avferagemonk'
Age of the user account (user_age)
66
Groups (including implicit) the user is in (user_groups)
[ 0 => '*', 1 => 'user' ]
Rights that the user has (user_rights)
[ 0 => 'createaccount', 1 => 'read', 2 => 'edit', 3 => 'createtalk', 4 => 'writeapi', 5 => 'viewmyprivateinfo', 6 => 'editmyprivateinfo', 7 => 'editmyoptions', 8 => 'abusefilter-log-detail', 9 => 'urlshortener-create-url', 10 => 'centralauth-merge', 11 => 'abusefilter-view', 12 => 'abusefilter-log', 13 => 'vipsscaler-test', 14 => 'collectionsaveasuserpage', 15 => 'reupload-own', 16 => 'move-rootuserpages', 17 => 'createpage', 18 => 'minoredit', 19 => 'editmyusercss', 20 => 'editmyuserjson', 21 => 'editmyuserjs', 22 => 'sendemail', 23 => 'applychangetags', 24 => 'viewmywatchlist', 25 => 'editmywatchlist', 26 => 'spamblacklistlog', 27 => 'mwoauthmanagemygrants' ]
Whether or not a user is editing through the mobile interface (user_mobile)
false
Whether the user is editing from mobile app (user_app)
false
Page ID (page_id)
582440
Page namespace (page_namespace)
0
Page title without namespace (page_title)
'Luhn algorithm'
Full page title (page_prefixedtitle)
'Luhn algorithm'
Edit protection level of the page (page_restrictions_edit)
[]
Last ten users to contribute to the page (page_recent_contributors)
[ 0 => 'Fgnievinski', 1 => 'Rkmuller', 2 => '12.179.93.202', 3 => '2601:2C1:9000:C00:0:0:0:36C0', 4 => '2804:431:CFDC:5603:4CB5:F091:5D7:68E2', 5 => '50.98.174.59', 6 => '2601:249:D02:57E0:E020:286B:33E8:6503', 7 => 'Mindmatrix', 8 => '103.161.56.253', 9 => 'TCMemoire' ]
Page age in seconds (page_age)
633889869
Action (action)
'edit'
Edit summary/reason (summary)
'/* Java */ '
Time since last page edit in seconds (page_last_edit_age)
24145
Old content model (old_content_model)
'wikitext'
New content model (new_content_model)
'wikitext'
Old page wikitext, before the edit (old_wikitext)
'{{Short description|Simple checksum formula}} The '''Luhn algorithm''' or '''Luhn formula''', also known as the "[[modular arithmetic|modulus]] 10" or "mod 10" [[algorithm]], named after its creator, [[IBM]] scientist [[Hans Peter Luhn]], is a simple [[check digit]] formula used to validate a variety of identification numbers. It is described in U.S. Patent No. 2,950,048, granted on August 23, 1960.<ref name="patent">{{cite patent |country=US |number=2950048A |status=patent |title=Computer for verifying numbers |pubdate=1960-08-23 |fdate=1954-01-06 |inventor1-first=Hans P. |inventor1-last=Luhn |inventorlink=Hans Peter Luhn}}</ref> The algorithm is in the [[public ___domain]] and is in wide use today. It is specified in [[ISO/IEC 7812-1]].<ref>{{cite tech report |title=Identification cards — Identification of issuers — Part 1: Numbering system |number=[[ISO/IEC 7812]]-1:2017 |institution=[[International Organization for Standardization]], [[International Electrotechnical Commission]] |date=January 2017 |type=Standard |url=https://www.iso.org/standard/70484.html |chapter=Annex B: Luhn formula for computing modulus-10 “double-add-double” check digits}}</ref> It is not intended to be a [[cryptographic hash function|cryptographically secure hash function]]; it was designed to protect against accidental errors, not malicious attacks. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from mistyped or otherwise incorrect numbers. ==Description== The check digit is computed as follows: # If the number already contains the check digit, drop that digit to form the "payload". The check digit is most often the last digit. # With the payload, start from the rightmost digit. Moving left, double the value of every second digit (including the rightmost digit). # Sum the values of the resulting digits. # The check digit is calculated by <math>(10 - (s \bmod 10)) \bmod 10</math>, where s is the sum from step 3. This is the smallest number (possibly zero) that must be added to <math>s</math> to make a multiple of 10. Other valid formulas giving the same value are <math>9 - ((s + 9)\bmod 10)</math>, <math>(10 - s)\bmod 10</math>, and <math>10\lceil s/10\rceil - s</math>. Note that the formula <math>(10 - s)\bmod 10</math> will not work in all environments due to differences in how negative numbers are handled by the [[modulo]] operation. === Example for computing check digit === Assume an example of an account number 1789372997 (just the "payload", check digit not yet included): {| class="wikitable" style="text-align:center;border:none;background:transparent;"4353464434047422| style="width:1.5em" | 4283039836977353| style="width:1.5em" | 9 | style="width:1.5em" | | style="width:1.5em" | 7 | style="width:1.5em" | 9 | style="width:1.5em" | 9 | style="width:1.5em" | 2 | style="width:1.5em" | 7 | style="width:1.5em" | 3 | style="width:1.5em" | 9 | style="width:1.5em" | 8 | style="width:1.5em" | 7 | style="width:1.5em" | 1 |- ! Multipliers | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 |- ! | = | = | = | = | = | = | = | = | = | = |- ! | style="background: #FFA;" | '''14''' | 9 | style="background: #FFA;" | '''18''' | 2 | style="background: #FFA;" | '''14''' | 3 | style="background: #FFA;" | '''18''' | 8 | style="background: #FFA;" | '''14''' | 1 |- ! Sum digits |'''5''' (1+4) |9 |'''9''' (1+8) |2 |'''5''' (1+4) |3 |'''9''' (1+8) |8 |'''5''' (1+4) |1 |} The sum of the resulting digits is 56. The check digit is equal to <math>(10 - (56\operatorname{mod} 10)) = 4</math>. This makes the full account number read 17893729974. === Example for validating check digit === # Drop the check digit (last digit) of the number to validate. (e.g. 17893729974 &rarr; 1789372997) # Calculate the check digit (see above) # Compare your result with the original check digit. If both numbers match, the result is valid. {{nowrap|1=(e.g. (givenCheckDigit = calculatedCheckDigit) &hArr; (isValidCheckDigit)).}} ==Strengths and weaknesses== The Luhn algorithm will detect all single-digit errors, as well as almost all transpositions of adjacent digits. It will not, however, detect transposition of the two-digit sequence ''09'' to ''90'' (or vice versa). It will detect most of the possible twin errors (it will not detect ''22'' ↔ ''55'', ''33'' ↔ ''66'' or ''44'' ↔ ''77''). Other, more complex check-digit algorithms (such as the [[Verhoeff algorithm]] and the [[Damm algorithm]]) can detect more transcription errors. The [[Luhn mod N algorithm]] is an extension that supports non-numerical strings. Because the algorithm operates on the digits in a right-to-left manner and zero digits affect the result only if they cause shift in position, zero-padding the beginning of a string of numbers does not affect the calculation. Therefore, systems that pad to a specific number of digits (by converting 1234 to 0001234 for instance) can perform Luhn validation before or after the padding and achieve the same result. The algorithm appeared in a United States Patent<ref name="patent" /> for a simple, hand-held, mechanical device for computing the checksum. The device took the mod 10 sum by mechanical means. The ''substitution digits'', that is, the results of the double and reduce procedure, were not produced mechanically. Rather, the digits were marked in their permuted order on the body of the machine. == 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..length]) 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''' cardNumber[length] == (10 - (sum mod 10)) '''end function''' == Code implementation == === [[C Sharp (programming language)|C#]] === <syntaxhighlight lang="c#" line="1"> bool IsValidLuhn(in int[1] digits) { int check_digit = 0; for (int i = digits.Length - 2; i >= 0; --i) check_digit += ((i & 1) is 0) switch { true => digits[i] > 4 ? digits[i] * 2 - 9 : digits[i] * 2, false => digits[i] }; return (10 - (check_digit % 10)) % 10 == digits.Last(); } </syntaxhighlight> === [[Java (programming language)|Java]] === <syntaxhighlight lang="java" line="1"> public static boolean isValidLuhn(String number) { int n = number.length(); int total = 0; boolean even = true; // iterate from right to left, double every 'even' value for (int i = n - 2; i >= 0; i--) { int digit = number.charAt(i) - '0'; if (digit < 0 || digit > 9) { // value may only contain digits return false; } if (even) { digit <<= 1; // double value } even = !even; total += digit > 9 ? digit - 9 : digit; } int checksum = number.charAt(n - 1) - '0'; return (total + checksum) % 10 == 0; } </syntaxhighlight> === [[TypeScript]] === <syntaxhighlight lang="typescript" line="1"> function luhnCheck(input: number): boolean { const number = input.toString(); const digits = number.replace(/\D/g, '').split('').map(Number); let sum = 0; let isSecond = false; for (let i = digits.length - 1; i >= 0; i--) { let digit = digits[i]; if (isSecond) { digit *= 2; if (digit > 9) { digit -= 9; } } sum += digit; isSecond = !isSecond; } return sum % 10 === 0; } </syntaxhighlight> == Uses == The Luhn algorithm is used in a variety of systems, including: * [[Payment card number|Credit card numbers]] * [[International Mobile Equipment Identity|IMEI numbers]] * [[National Provider Identifier|National Provider Identifier numbers]] in the United States * [[Canada|Canadian]] [[social insurance number]]s * [[Israeli identity card|Israeli]] ID numbers * [[South Africa|South African]] ID numbers * [[South Africa|South African]] Tax reference numbers * [[Sweden|Swedish]] [[national identification number]]s * [[Sweden|Swedish]] Corporate Identity Numbers (OrgNr) * [[Greece|Greek]] Social Security Numbers (ΑΜΚΑ) * [[SIM_card#ICCID|ICCID]] of SIM cards * [[European Patent Convention|European patent]] application numbers * Survey codes appearing on [[:File:McDonalds Receipt Luhn Algorithm.png|McDonald's]], [[:File:Taco Bell Receipt Luhn Algorithm.png|Taco Bell]], and [[:File:Tractor Supply Receipt Luhn Algorithm.png|Tractor Supply Co.]] receipts * [[United States Postal Service]] package tracking numbers use a modified Luhn algorithm<ref>{{cite web |title=Publication 199: Intelligent Mail Package Barcode (IMpb) Implementation Guide for Confirmation Services and Electronic Payment Systems |url=https://postalpro.usps.com/pub199 |publisher=United States Postal Service |access-date=29 November 2023}}</ref> ==References== <references/> ==External links== * [https://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers Implementation in 150 languages on the Rosetta Code project] {{DEFAULTSORT:Luhn Algorithm}} [[Category:Modular arithmetic]] [[Category:Checksum algorithms]] [[Category:Error detection and correction]] [[Category:1954 introductions]] [[Category:Articles with example pseudocode]] [[Category:Management cybernetics]]'
New page wikitext, after the edit (new_wikitext)
'{{Short description|Simple checksum formula}} The '''Luhn algorithm''' or '''Luhn formula''', also known as the "[[modular arithmetic|modulus]] 10" or "mod 10" [[algorithm]], named after its creator, [[IBM]] scientist [[Hans Peter Luhn]], is a simple [[check digit]] formula used to validate a variety of identification numbers. It is described in U.S. Patent No. 2,950,048, granted on August 23, 1960.<ref name="patent">{{cite patent |country=US |number=2950048A |status=patent |title=Computer for verifying numbers |pubdate=1960-08-23 |fdate=1954-01-06 |inventor1-first=Hans P. |inventor1-last=Luhn |inventorlink=Hans Peter Luhn}}</ref> The algorithm is in the [[public ___domain]] and is in wide use today. It is specified in [[ISO/IEC 7812-1]].<ref>{{cite tech report |title=Identification cards — Identification of issuers — Part 1: Numbering system |number=[[ISO/IEC 7812]]-1:2017 |institution=[[International Organization for Standardization]], [[International Electrotechnical Commission]] |date=January 2017 |type=Standard |url=https://www.iso.org/standard/70484.html |chapter=Annex B: Luhn formula for computing modulus-10 “double-add-double” check digits}}</ref> It is not intended to be a [[cryptographic hash function|cryptographically secure hash function]]; it was designed to protect against accidental errors, not malicious attacks. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from mistyped or otherwise incorrect numbers. ==Description== The check digit is computed as follows: # If the number already contains the check digit, drop that digit to form the "payload". The check digit is most often the last digit. # With the payload, start from the rightmost digit. Moving left, double the value of every second digit (including the rightmost digit). # Sum the values of the resulting digits. # The check digit is calculated by <math>(10 - (s \bmod 10)) \bmod 10</math>, where s is the sum from step 3. This is the smallest number (possibly zero) that must be added to <math>s</math> to make a multiple of 10. Other valid formulas giving the same value are <math>9 - ((s + 9)\bmod 10)</math>, <math>(10 - s)\bmod 10</math>, and <math>10\lceil s/10\rceil - s</math>. Note that the formula <math>(10 - s)\bmod 10</math> will not work in all environments due to differences in how negative numbers are handled by the [[modulo]] operation. === Example for computing check digit === Assume an example of an account number 1789372997 (just the "payload", check digit not yet included): {| class="wikitable" style="text-align:center;border:none;background:transparent;"4353464434047422| style="width:1.5em" | 4283039836977353| style="width:1.5em" | 9 | style="width:1.5em" | | style="width:1.5em" | 7 | style="width:1.5em" | 9 | style="width:1.5em" | 9 | style="width:1.5em" | 2 | style="width:1.5em" | 7 | style="width:1.5em" | 3 | style="width:1.5em" | 9 | style="width:1.5em" | 8 | style="width:1.5em" | 7 | style="width:1.5em" | 1 |- ! Multipliers | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 | 2 | 1 |- ! | = | = | = | = | = | = | = | = | = | = |- ! | style="background: #FFA;" | '''14''' | 9 | style="background: #FFA;" | '''18''' | 2 | style="background: #FFA;" | '''14''' | 3 | style="background: #FFA;" | '''18''' | 8 | style="background: #FFA;" | '''14''' | 1 |- ! Sum digits |'''5''' (1+4) |9 |'''9''' (1+8) |2 |'''5''' (1+4) |3 |'''9''' (1+8) |8 |'''5''' (1+4) |1 |} The sum of the resulting digits is 56. The check digit is equal to <math>(10 - (56\operatorname{mod} 10)) = 4</math>. This makes the full account number read 17893729974. === Example for validating check digit === # Drop the check digit (last digit) of the number to validate. (e.g. 17893729974 &rarr; 1789372997) # Calculate the check digit (see above) # Compare your result with the original check digit. If both numbers match, the result is valid. {{nowrap|1=(e.g. (givenCheckDigit = calculatedCheckDigit) &hArr; (isValidCheckDigit)).}} ==Strengths and weaknesses== The Luhn algorithm will detect all single-digit errors, as well as almost all transpositions of adjacent digits. It will not, however, detect transposition of the two-digit sequence ''09'' to ''90'' (or vice versa). It will detect most of the possible twin errors (it will not detect ''22'' ↔ ''55'', ''33'' ↔ ''66'' or ''44'' ↔ ''77''). Other, more complex check-digit algorithms (such as the [[Verhoeff algorithm]] and the [[Damm algorithm]]) can detect more transcription errors. The [[Luhn mod N algorithm]] is an extension that supports non-numerical strings. Because the algorithm operates on the digits in a right-to-left manner and zero digits affect the result only if they cause shift in position, zero-padding the beginning of a string of numbers does not affect the calculation. Therefore, systems that pad to a specific number of digits (by converting 1234 to 0001234 for instance) can perform Luhn validation before or after the padding and achieve the same result. The algorithm appeared in a United States Patent<ref name="patent" /> for a simple, hand-held, mechanical device for computing the checksum. The device took the mod 10 sum by mechanical means. The ''substitution digits'', that is, the results of the double and reduce procedure, were not produced mechanically. Rather, the digits were marked in their permuted order on the body of the machine. == 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..length]) 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''' cardNumber[length] == (10 - (sum mod 10)) '''end function''' == Code implementation == === [[C Sharp (programming language)|C#]] === <syntaxhighlight lang="c#" line="1"> bool IsValidLuhn(in int[1] digits) { int check_digit = 0; for (int i = digits.Length - 2; i >= 0; --i) check_digit += ((i & 1) is 0) switch { true => digits[i] > 4 ? digits[i] * 2 - 9 : digits[i] * 2, false => digits[i] }; return (10 - (check_digit % 10)) % 10 == digits.Last(); } </syntaxhighlight> erm what the sigma v v v vv v v v v sadf asd as d asd satg ggg g g gg g g g g g gg g g g === [[TypeScript]] === <syntaxhighlight lang="typescript" line="1"> function luhnCheck(input: number): boolean { const number = input.toString(); const digits = number.replace(/\D/g, '').split('').map(Number); let sum = 0; let isSecond = false; for (let i = digits.length - 1; i >= 0; i--) { let digit = digits[i]; if (isSecond) { digit *= 2; if (digit > 9) { digit -= 9; } } sum += digit; isSecond = !isSecond; } return sum % 10 === 0; } </syntaxhighlight> == Uses == The Luhn algorithm is used in a variety of systems, including: * [[Payment card number|Credit card numbers]] * [[International Mobile Equipment Identity|IMEI numbers]] * [[National Provider Identifier|National Provider Identifier numbers]] in the United States * [[Canada|Canadian]] [[social insurance number]]s * [[Israeli identity card|Israeli]] ID numbers * [[South Africa|South African]] ID numbers * [[South Africa|South African]] Tax reference numbers * [[Sweden|Swedish]] [[national identification number]]s * [[Sweden|Swedish]] Corporate Identity Numbers (OrgNr) * [[Greece|Greek]] Social Security Numbers (ΑΜΚΑ) * [[SIM_card#ICCID|ICCID]] of SIM cards * [[European Patent Convention|European patent]] application numbers * Survey codes appearing on [[:File:McDonalds Receipt Luhn Algorithm.png|McDonald's]], [[:File:Taco Bell Receipt Luhn Algorithm.png|Taco Bell]], and [[:File:Tractor Supply Receipt Luhn Algorithm.png|Tractor Supply Co.]] receipts * [[United States Postal Service]] package tracking numbers use a modified Luhn algorithm<ref>{{cite web |title=Publication 199: Intelligent Mail Package Barcode (IMpb) Implementation Guide for Confirmation Services and Electronic Payment Systems |url=https://postalpro.usps.com/pub199 |publisher=United States Postal Service |access-date=29 November 2023}}</ref> ==References== <references/> ==External links== * [https://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers Implementation in 150 languages on the Rosetta Code project] {{DEFAULTSORT:Luhn Algorithm}} [[Category:Modular arithmetic]] [[Category:Checksum algorithms]] [[Category:Error detection and correction]] [[Category:1954 introductions]] [[Category:Articles with example pseudocode]] [[Category:Management cybernetics]]'
Unified diff of changes made by edit (edit_diff)
'@@ -136,27 +136,32 @@ </syntaxhighlight> -=== [[Java (programming language)|Java]] === -<syntaxhighlight lang="java" line="1"> -public static boolean isValidLuhn(String number) { - int n = number.length(); - int total = 0; - boolean even = true; - // iterate from right to left, double every 'even' value - for (int i = n - 2; i >= 0; i--) { - int digit = number.charAt(i) - '0'; - if (digit < 0 || digit > 9) { - // value may only contain digits - return false; - } - if (even) { - digit <<= 1; // double value - } - even = !even; - total += digit > 9 ? digit - 9 : digit; - } - int checksum = number.charAt(n - 1) - '0'; - return (total + checksum) % 10 == 0; -} -</syntaxhighlight> +erm what the sigma +v +v +v +vv +v +v +v +v +sadf +asd +as +d +asd +satg +ggg +g +g +gg +g +g +g +g +g +gg +g +g +g === [[TypeScript]] === '
New page size (new_size)
9000
Old page size (old_size)
9638
Size change in edit (edit_delta)
-638
Lines added in edit (added_lines)
[ 0 => 'erm what the sigma', 1 => 'v', 2 => 'v', 3 => 'v', 4 => 'vv', 5 => 'v', 6 => 'v', 7 => 'v', 8 => 'v', 9 => 'sadf', 10 => 'asd', 11 => 'as', 12 => 'd', 13 => 'asd', 14 => 'satg', 15 => 'ggg', 16 => 'g', 17 => 'g', 18 => 'gg', 19 => 'g', 20 => 'g', 21 => 'g', 22 => 'g', 23 => 'g', 24 => 'gg', 25 => 'g', 26 => 'g', 27 => 'g' ]
Lines removed in edit (removed_lines)
[ 0 => '=== [[Java (programming language)|Java]] ===', 1 => '<syntaxhighlight lang="java" line="1">', 2 => 'public static boolean isValidLuhn(String number) {', 3 => ' int n = number.length();', 4 => ' int total = 0;', 5 => ' boolean even = true;', 6 => ' // iterate from right to left, double every 'even' value', 7 => ' for (int i = n - 2; i >= 0; i--) {', 8 => ' int digit = number.charAt(i) - '0';', 9 => ' if (digit < 0 || digit > 9) {', 10 => ' // value may only contain digits', 11 => ' return false;', 12 => ' }', 13 => ' if (even) {', 14 => ' digit <<= 1; // double value', 15 => ' }', 16 => ' even = !even;', 17 => ' total += digit > 9 ? digit - 9 : digit;', 18 => ' }', 19 => ' int checksum = number.charAt(n - 1) - '0';', 20 => ' return (total + checksum) % 10 == 0;', 21 => '}', 22 => '</syntaxhighlight>' ]
Parsed HTML source of the new revision (new_html)
'<div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><div class="shortdescription nomobile noexcerpt noprint searchaux" style="display:none">Simple checksum formula</div> <p>The <b>Luhn algorithm</b> or <b>Luhn formula</b>, also known as the "<a href="/wiki/Modular_arithmetic" title="Modular arithmetic">modulus</a> 10" or "mod 10" <a href="/wiki/Algorithm" title="Algorithm">algorithm</a>, named after its creator, <a href="/wiki/IBM" title="IBM">IBM</a> scientist <a href="/wiki/Hans_Peter_Luhn" title="Hans Peter Luhn">Hans Peter Luhn</a>, is a simple <a href="/wiki/Check_digit" title="Check digit">check digit</a> formula used to validate a variety of identification numbers. It is described in U.S. Patent No. 2,950,048, granted on August 23, 1960.<sup id="cite_ref-patent_1-0" class="reference"><a href="#cite_note-patent-1">&#91;1&#93;</a></sup> </p><p>The algorithm is in the <a href="/wiki/Public_domain" title="Public ___domain">public ___domain</a> and is in wide use today. It is specified in <a href="/wiki/ISO/IEC_7812-1" class="mw-redirect" title="ISO/IEC 7812-1">ISO/IEC 7812-1</a>.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2">&#91;2&#93;</a></sup> It is not intended to be a <a href="/wiki/Cryptographic_hash_function" title="Cryptographic hash function">cryptographically secure hash function</a>; it was designed to protect against accidental errors, not malicious attacks. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from mistyped or otherwise incorrect numbers. </p> <div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div> <ul> <li class="toclevel-1 tocsection-1"><a href="#Description"><span class="tocnumber">1</span> <span class="toctext">Description</span></a> <ul> <li class="toclevel-2 tocsection-2"><a href="#Example_for_computing_check_digit"><span class="tocnumber">1.1</span> <span class="toctext">Example for computing check digit</span></a></li> <li class="toclevel-2 tocsection-3"><a href="#Example_for_validating_check_digit"><span class="tocnumber">1.2</span> <span class="toctext">Example for validating check digit</span></a></li> </ul> </li> <li class="toclevel-1 tocsection-4"><a href="#Strengths_and_weaknesses"><span class="tocnumber">2</span> <span class="toctext">Strengths and weaknesses</span></a></li> <li class="toclevel-1 tocsection-5"><a href="#Pseudocode_implementation"><span class="tocnumber">3</span> <span class="toctext">Pseudocode implementation</span></a></li> <li class="toclevel-1 tocsection-6"><a href="#Code_implementation"><span class="tocnumber">4</span> <span class="toctext">Code implementation</span></a> <ul> <li class="toclevel-2 tocsection-7"><a href="#C#"><span class="tocnumber">4.1</span> <span class="toctext">C#</span></a></li> <li class="toclevel-2 tocsection-8"><a href="#TypeScript"><span class="tocnumber">4.2</span> <span class="toctext">TypeScript</span></a></li> </ul> </li> <li class="toclevel-1 tocsection-9"><a href="#Uses"><span class="tocnumber">5</span> <span class="toctext">Uses</span></a></li> <li class="toclevel-1 tocsection-10"><a href="#References"><span class="tocnumber">6</span> <span class="toctext">References</span></a></li> <li class="toclevel-1 tocsection-11"><a href="#External_links"><span class="tocnumber">7</span> <span class="toctext">External links</span></a></li> </ul> </div> <h2><span class="mw-headline" id="Description">Description</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Luhn_algorithm&amp;action=edit&amp;section=1" title="Edit section&#039;s source code: Description"><span>edit source</span></a><span class="mw-editsection-bracket">]</span></span></h2> <p>The check digit is computed as follows: </p> <ol><li>If the number already contains the check digit, drop that digit to form the "payload". The check digit is most often the last digit.</li> <li>With the payload, start from the rightmost digit. Moving left, double the value of every second digit (including the rightmost digit).</li> <li>Sum the values of the resulting digits.</li> <li>The check digit is calculated by <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle (10-(s{\bmod {1}}0)){\bmod {1}}0}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">(</mo> <mn>10</mn> <mo>&#x2212;<!-- − --></mo> <mo stretchy="false">(</mo> <mi>s</mi> <mrow class="MJX-TeXAtom-ORD"> <mo lspace="thickmathspace" rspace="thickmathspace">mod</mo> <mrow class="MJX-TeXAtom-ORD"> <mn>1</mn> </mrow> </mrow> <mn>0</mn> <mo stretchy="false">)</mo> <mo stretchy="false">)</mo> <mrow class="MJX-TeXAtom-ORD"> <mo lspace="thickmathspace" rspace="thickmathspace">mod</mo> <mrow class="MJX-TeXAtom-ORD"> <mn>1</mn> </mrow> </mrow> <mn>0</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle (10-(s{\bmod {1}}0)){\bmod {1}}0}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/9178b597d6168b66cfa8c99aeb1a32cd2467327e" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:25.887ex; height:2.843ex;" alt="{\displaystyle (10-(s{\bmod {1}}0)){\bmod {1}}0}"></span>, where s is the sum from step 3. This is the smallest number (possibly zero) that must be added to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle s}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mi>s</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle s}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/01d131dfd7673938b947072a13a9744fe997e632" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.09ex; height:1.676ex;" alt="{\displaystyle s}"></span> to make a multiple of 10. Other valid formulas giving the same value are <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 9-((s+9){\bmod {1}}0)}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mn>9</mn> <mo>&#x2212;<!-- − --></mo> <mo stretchy="false">(</mo> <mo stretchy="false">(</mo> <mi>s</mi> <mo>+</mo> <mn>9</mn> <mo stretchy="false">)</mo> <mrow class="MJX-TeXAtom-ORD"> <mo lspace="thickmathspace" rspace="thickmathspace">mod</mo> <mrow class="MJX-TeXAtom-ORD"> <mn>1</mn> </mrow> </mrow> <mn>0</mn> <mo stretchy="false">)</mo> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle 9-((s+9){\bmod {1}}0)}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/87a7817f16fac5c24dbf45d6319ddf3cc48b744a" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:20.721ex; height:2.843ex;" alt="{\displaystyle 9-((s+9){\bmod {1}}0)}"></span>, <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle (10-s){\bmod {1}}0}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">(</mo> <mn>10</mn> <mo>&#x2212;<!-- − --></mo> <mi>s</mi> <mo stretchy="false">)</mo> <mrow class="MJX-TeXAtom-ORD"> <mo lspace="thickmathspace" rspace="thickmathspace">mod</mo> <mrow class="MJX-TeXAtom-ORD"> <mn>1</mn> </mrow> </mrow> <mn>0</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle (10-s){\bmod {1}}0}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/91929ceecbe622b2298a8254f7220e28ccf43166" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:16.071ex; height:2.843ex;" alt="{\displaystyle (10-s){\bmod {1}}0}"></span>, and <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 10\lceil s/10\rceil -s}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mn>10</mn> <mo fence="false" stretchy="false">&#x2308;<!-- ⌈ --></mo> <mi>s</mi> <mrow class="MJX-TeXAtom-ORD"> <mo>/</mo> </mrow> <mn>10</mn> <mo fence="false" stretchy="false">&#x2309;<!-- ⌉ --></mo> <mo>&#x2212;<!-- − --></mo> <mi>s</mi> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle 10\lceil s/10\rceil -s}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/3da5e6ac2ce15ed3c950766dd53d5206ee747201" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:12.898ex; height:2.843ex;" alt="{\displaystyle 10\lceil s/10\rceil -s}"></span>. Note that the formula <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle (10-s){\bmod {1}}0}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">(</mo> <mn>10</mn> <mo>&#x2212;<!-- − --></mo> <mi>s</mi> <mo stretchy="false">)</mo> <mrow class="MJX-TeXAtom-ORD"> <mo lspace="thickmathspace" rspace="thickmathspace">mod</mo> <mrow class="MJX-TeXAtom-ORD"> <mn>1</mn> </mrow> </mrow> <mn>0</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle (10-s){\bmod {1}}0}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/91929ceecbe622b2298a8254f7220e28ccf43166" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:16.071ex; height:2.843ex;" alt="{\displaystyle (10-s){\bmod {1}}0}"></span> will not work in all environments due to differences in how negative numbers are handled by the <a href="/wiki/Modulo" title="Modulo">modulo</a> operation.</li></ol> <h3><span class="mw-headline" id="Example_for_computing_check_digit">Example for computing check digit</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Luhn_algorithm&amp;action=edit&amp;section=2" title="Edit section&#039;s source code: Example for computing check digit"><span>edit source</span></a><span class="mw-editsection-bracket">]</span></span></h3> <p>Assume an example of an account number 1789372997 (just the "payload", check digit not yet included): </p> <table class="wikitable" style="width:1.5em"> <tbody><tr> <td style="width:1.5em"> </td> <td style="width:1.5em">7 </td> <td style="width:1.5em">9 </td> <td style="width:1.5em">9 </td> <td style="width:1.5em">2 </td> <td style="width:1.5em">7 </td> <td style="width:1.5em">3 </td> <td style="width:1.5em">9 </td> <td style="width:1.5em">8 </td> <td style="width:1.5em">7 </td> <td style="width:1.5em">1 </td></tr> <tr> <th>Multipliers </th> <td>2 </td> <td>1 </td> <td>2 </td> <td>1 </td> <td>2 </td> <td>1 </td> <td>2 </td> <td>1 </td> <td>2 </td> <td>1 </td></tr> <tr> <th> </th> <td>= </td> <td>= </td> <td>= </td> <td>= </td> <td>= </td> <td>= </td> <td>= </td> <td>= </td> <td>= </td> <td>= </td></tr> <tr> <th> </th> <td style="background: #FFA;"><b>14</b> </td> <td>9 </td> <td style="background: #FFA;"><b>18</b> </td> <td>2 </td> <td style="background: #FFA;"><b>14</b> </td> <td>3 </td> <td style="background: #FFA;"><b>18</b> </td> <td>8 </td> <td style="background: #FFA;"><b>14</b> </td> <td>1 </td></tr> <tr> <th>Sum digits </th> <td><b>5</b> (1+4) </td> <td>9 </td> <td><b>9</b> (1+8) </td> <td>2 </td> <td><b>5</b> (1+4) </td> <td>3 </td> <td><b>9</b> (1+8) </td> <td>8 </td> <td><b>5</b> (1+4) </td> <td>1 </td></tr></tbody></table> <p>The sum of the resulting digits is 56. </p><p>The check digit is equal to <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle (10-(56\operatorname {mod} 10))=4}"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mo stretchy="false">(</mo> <mn>10</mn> <mo>&#x2212;<!-- − --></mo> <mo stretchy="false">(</mo> <mn>56</mn> <mi>mod</mi> <mo>&#x2061;<!-- ⁡ --></mo> <mn>10</mn> <mo stretchy="false">)</mo> <mo stretchy="false">)</mo> <mo>=</mo> <mn>4</mn> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle (10-(56\operatorname {mod} 10))=4}</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/ee6bede6297e5788fa10635b37f2b4f4243f9ca3" class="mwe-math-fallback-image-inline mw-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:22.86ex; height:2.843ex;" alt="{\displaystyle (10-(56\operatorname {mod} 10))=4}"></span>. </p><p>This makes the full account number read 17893729974. </p> <h3><span class="mw-headline" id="Example_for_validating_check_digit">Example for validating check digit</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Luhn_algorithm&amp;action=edit&amp;section=3" title="Edit section&#039;s source code: Example for validating check digit"><span>edit source</span></a><span class="mw-editsection-bracket">]</span></span></h3> <ol><li>Drop the check digit (last digit) of the number to validate. (e.g. 17893729974 &#8594; 1789372997)</li> <li>Calculate the check digit (see above)</li> <li>Compare your result with the original check digit. If both numbers match, the result is valid. <span class="nowrap">(e.g. (givenCheckDigit = calculatedCheckDigit) &#8660; (isValidCheckDigit)).</span></li></ol> <h2><span class="mw-headline" id="Strengths_and_weaknesses">Strengths and weaknesses</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Luhn_algorithm&amp;action=edit&amp;section=4" title="Edit section&#039;s source code: Strengths and weaknesses"><span>edit source</span></a><span class="mw-editsection-bracket">]</span></span></h2> <p>The Luhn algorithm will detect all single-digit errors, as well as almost all transpositions of adjacent digits. It will not, however, detect transposition of the two-digit sequence <i>09</i> to <i>90</i> (or vice versa). It will detect most of the possible twin errors (it will not detect <i>22</i> ↔ <i>55</i>, <i>33</i> ↔ <i>66</i> or <i>44</i> ↔ <i>77</i>). </p><p>Other, more complex check-digit algorithms (such as the <a href="/wiki/Verhoeff_algorithm" title="Verhoeff algorithm">Verhoeff algorithm</a> and the <a href="/wiki/Damm_algorithm" title="Damm algorithm">Damm algorithm</a>) can detect more transcription errors. The <a href="/wiki/Luhn_mod_N_algorithm" title="Luhn mod N algorithm">Luhn mod N algorithm</a> is an extension that supports non-numerical strings. </p><p>Because the algorithm operates on the digits in a right-to-left manner and zero digits affect the result only if they cause shift in position, zero-padding the beginning of a string of numbers does not affect the calculation. Therefore, systems that pad to a specific number of digits (by converting 1234 to 0001234 for instance) can perform Luhn validation before or after the padding and achieve the same result. </p><p>The algorithm appeared in a United States Patent<sup id="cite_ref-patent_1-1" class="reference"><a href="#cite_note-patent-1">&#91;1&#93;</a></sup> for a simple, hand-held, mechanical device for computing the checksum. The device took the mod 10 sum by mechanical means. The <i>substitution digits</i>, that is, the results of the double and reduce procedure, were not produced mechanically. Rather, the digits were marked in their permuted order on the body of the machine. </p> <h2><span class="mw-headline" id="Pseudocode_implementation">Pseudocode implementation</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Luhn_algorithm&amp;action=edit&amp;section=5" title="Edit section&#039;s source code: Pseudocode implementation"><span>edit source</span></a><span class="mw-editsection-bracket">]</span></span></h2> <p>The following function takes a card number, including the check digit, as an array of integers and outputs <b>true</b> if the check digit is correct, <b>false</b> otherwise. </p> <pre><b>function</b> isValid(cardNumber[1..length]) sum&#160;:= 0 parity&#160;:= length mod 2 <b>for</b> i from 1 to length <b>do</b> <b>if</b> i mod 2&#160;!= parity <b>then</b> sum&#160;:= sum + cardNumber[i] <b>elseif</b> cardNumber[i] &gt; 4 <b>then</b> sum&#160;:= sum + 2 * cardNumber[i] - 9 <b>else</b> sum&#160;:= sum + 2 * cardNumber[i] <b>end if</b> <b>end for</b> <b>return</b> cardNumber[length] == (10 - (sum mod 10)) <b>end function</b> </pre> <h2><span class="mw-headline" id="Code_implementation">Code implementation</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Luhn_algorithm&amp;action=edit&amp;section=6" title="Edit section&#039;s source code: Code implementation"><span>edit source</span></a><span class="mw-editsection-bracket">]</span></span></h2> <h3><span id="C.23"></span><span class="mw-headline" id="C#"><a href="/wiki/C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Luhn_algorithm&amp;action=edit&amp;section=7" title="Edit section&#039;s source code: C#"><span>edit source</span></a><span class="mw-editsection-bracket">]</span></span></h3> <div class="mw-highlight mw-highlight-lang-c# mw-content-ltr mw-highlight-lines" dir="ltr"><pre><span></span><span class="linenos" data-line="1"></span><span class="kt">bool</span><span class="w"> </span><span class="nf">IsValidLuhn</span><span class="p">(</span><span class="k">in</span><span class="w"> </span><span class="kt">int</span><span class="p">[</span><span class="m">1</span><span class="p">]</span><span class="w"> </span><span class="n">digits</span><span class="p">)</span> <span class="linenos" data-line="2"></span><span class="p">{</span> <span class="linenos" data-line="3"></span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">check_digit</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">0</span><span class="p">;</span> <span class="linenos" data-line="4"></span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">digits</span><span class="p">.</span><span class="n">Length</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">2</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&gt;=</span><span class="w"> </span><span class="m">0</span><span class="p">;</span><span class="w"> </span><span class="o">--</span><span class="n">i</span><span class="p">)</span> <span class="linenos" data-line="5"></span><span class="w"> </span><span class="n">check_digit</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="p">((</span><span class="n">i</span><span class="w"> </span><span class="o">&amp;</span><span class="w"> </span><span class="m">1</span><span class="p">)</span><span class="w"> </span><span class="k">is</span><span class="w"> </span><span class="m">0</span><span class="p">)</span><span class="w"> </span><span class="k">switch</span> <span class="linenos" data-line="6"></span><span class="w"> </span><span class="p">{</span> <span class="linenos" data-line="7"></span><span class="w"> </span><span class="k">true</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">digits</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="m">4</span><span class="w"> </span><span class="o">?</span><span class="w"> </span><span class="n">digits</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="m">2</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="m">9</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">digits</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="m">2</span><span class="p">,</span> <span class="linenos" data-line="8"></span><span class="w"> </span><span class="k">false</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">digits</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="linenos" data-line="9"></span><span class="w"> </span><span class="p">};</span> <span class="linenos" data-line="10"></span> <span class="linenos" data-line="11"></span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="p">(</span><span class="m">10</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="p">(</span><span class="n">check_digit</span><span class="w"> </span><span class="o">%</span><span class="w"> </span><span class="m">10</span><span class="p">))</span><span class="w"> </span><span class="o">%</span><span class="w"> </span><span class="m">10</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">digits</span><span class="p">.</span><span class="n">Last</span><span class="p">();</span> <span class="linenos" data-line="12"></span><span class="p">}</span> </pre></div> <p>erm what the sigma v v v vv v v v v sadf asd as d asd satg ggg g g gg g g g g g gg g g g </p> <h3><span class="mw-headline" id="TypeScript"><a href="/wiki/TypeScript" title="TypeScript">TypeScript</a></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Luhn_algorithm&amp;action=edit&amp;section=8" title="Edit section&#039;s source code: TypeScript"><span>edit source</span></a><span class="mw-editsection-bracket">]</span></span></h3> <div class="mw-highlight mw-highlight-lang-typescript mw-content-ltr mw-highlight-lines" dir="ltr"><pre><span></span><span class="linenos" data-line="1"></span><span class="kd">function</span><span class="w"> </span><span class="nx">luhnCheck</span><span class="p">(</span><span class="nx">input</span><span class="o">:</span><span class="w"> </span><span class="kt">number</span><span class="p">)</span><span class="o">:</span><span class="w"> </span><span class="kt">boolean</span><span class="w"> </span><span class="p">{</span> <span class="linenos" data-line="2"></span><span class="w"> </span><span class="kd">const</span><span class="w"> </span><span class="kt">number</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">input</span><span class="p">.</span><span class="nx">toString</span><span class="p">();</span> <span class="linenos" data-line="3"></span><span class="w"> </span><span class="kd">const</span><span class="w"> </span><span class="nx">digits</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kt">number</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\D/g</span><span class="p">,</span><span class="w"> </span><span class="s1">&#39;&#39;</span><span class="p">).</span><span class="nx">split</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">).</span><span class="nx">map</span><span class="p">(</span><span class="nb">Number</span><span class="p">);</span> <span class="linenos" data-line="4"></span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nx">sum</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">0</span><span class="p">;</span> <span class="linenos" data-line="5"></span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nx">isSecond</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="p">;</span> <span class="linenos" data-line="6"></span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kd">let</span><span class="w"> </span><span class="nx">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">digits</span><span class="p">.</span><span class="nx">length</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mf">1</span><span class="p">;</span><span class="w"> </span><span class="nx">i</span><span class="w"> </span><span class="o">&gt;=</span><span class="w"> </span><span class="mf">0</span><span class="p">;</span><span class="w"> </span><span class="nx">i</span><span class="o">--</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="linenos" data-line="7"></span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nx">digit</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">digits</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span> <span class="linenos" data-line="8"></span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="nx">isSecond</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="linenos" data-line="9"></span><span class="w"> </span><span class="nx">digit</span><span class="w"> </span><span class="o">*=</span><span class="w"> </span><span class="mf">2</span><span class="p">;</span> <span class="linenos" data-line="10"></span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="nx">digit</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mf">9</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="linenos" data-line="11"></span><span class="w"> </span><span class="nx">digit</span><span class="w"> </span><span class="o">-=</span><span class="w"> </span><span class="mf">9</span><span class="p">;</span> <span class="linenos" data-line="12"></span><span class="w"> </span><span class="p">}</span> <span class="linenos" data-line="13"></span><span class="w"> </span><span class="p">}</span> <span class="linenos" data-line="14"></span><span class="w"> </span><span class="nx">sum</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="nx">digit</span><span class="p">;</span> <span class="linenos" data-line="15"></span><span class="w"> </span><span class="nx">isSecond</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">!</span><span class="nx">isSecond</span><span class="p">;</span> <span class="linenos" data-line="16"></span><span class="w"> </span><span class="p">}</span> <span class="linenos" data-line="17"></span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nx">sum</span><span class="w"> </span><span class="o">%</span><span class="w"> </span><span class="mf">10</span><span class="w"> </span><span class="o">===</span><span class="w"> </span><span class="mf">0</span><span class="p">;</span> <span class="linenos" data-line="18"></span><span class="p">}</span> </pre></div> <h2><span class="mw-headline" id="Uses">Uses</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Luhn_algorithm&amp;action=edit&amp;section=9" title="Edit section&#039;s source code: Uses"><span>edit source</span></a><span class="mw-editsection-bracket">]</span></span></h2> <p>The Luhn algorithm is used in a variety of systems, including: </p> <ul><li><a href="/wiki/Payment_card_number" title="Payment card number">Credit card numbers</a></li> <li><a href="/wiki/International_Mobile_Equipment_Identity" title="International Mobile Equipment Identity">IMEI numbers</a></li> <li><a href="/wiki/National_Provider_Identifier" title="National Provider Identifier">National Provider Identifier numbers</a> in the United States</li> <li><a href="/wiki/Canada" title="Canada">Canadian</a> <a href="/wiki/Social_insurance_number" title="Social insurance number">social insurance numbers</a></li> <li><a href="/wiki/Israeli_identity_card" title="Israeli identity card">Israeli</a> ID numbers</li> <li><a href="/wiki/South_Africa" title="South Africa">South African</a> ID numbers</li> <li><a href="/wiki/South_Africa" title="South Africa">South African</a> Tax reference numbers</li> <li><a href="/wiki/Sweden" title="Sweden">Swedish</a> <a href="/wiki/National_identification_number" title="National identification number">national identification numbers</a></li> <li><a href="/wiki/Sweden" title="Sweden">Swedish</a> Corporate Identity Numbers (OrgNr)</li> <li><a href="/wiki/Greece" title="Greece">Greek</a> Social Security Numbers (ΑΜΚΑ)</li> <li><a href="/wiki/SIM_card#ICCID" title="SIM card">ICCID</a> of SIM cards</li> <li><a href="/wiki/European_Patent_Convention" title="European Patent Convention">European patent</a> application numbers</li> <li>Survey codes appearing on <a href="/wiki/File:McDonalds_Receipt_Luhn_Algorithm.png" title="File:McDonalds Receipt Luhn Algorithm.png">McDonald's</a>, <a href="/wiki/File:Taco_Bell_Receipt_Luhn_Algorithm.png" title="File:Taco Bell Receipt Luhn Algorithm.png">Taco Bell</a>, and <a href="/wiki/File:Tractor_Supply_Receipt_Luhn_Algorithm.png" title="File:Tractor Supply Receipt Luhn Algorithm.png">Tractor Supply Co.</a> receipts</li> <li><a href="/wiki/United_States_Postal_Service" title="United States Postal Service">United States Postal Service</a> package tracking numbers use a modified Luhn algorithm<sup id="cite_ref-3" class="reference"><a href="#cite_note-3">&#91;3&#93;</a></sup></li></ul> <h2><span class="mw-headline" id="References">References</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Luhn_algorithm&amp;action=edit&amp;section=10" title="Edit section&#039;s source code: References"><span>edit source</span></a><span class="mw-editsection-bracket">]</span></span></h2> <div class="mw-references-wrap"><ol class="references"> <li id="cite_note-patent-1"><span class="mw-cite-backlink">^ <a href="#cite_ref-patent_1-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-patent_1-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1041539562">.mw-parser-output .citation{word-wrap:break-word}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}</style><span class="citation patent" id="CITEREFLuhn1960"><a rel="nofollow" class="external text" href="https://worldwide.espacenet.com/textdoc?DB=EPODOC&amp;IDX=US2950048A">US&#32;patent 2950048A</a>,&#32;<a href="/wiki/Hans_Peter_Luhn" title="Hans Peter Luhn">Luhn, Hans P.</a>,&#32;"Computer for verifying numbers",&#32;published 1960-08-23</span><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Apatent&amp;rft.number=2950048A&amp;rft.cc=US&amp;rft.title=Computer+for+verifying+numbers&amp;rft.inventor=Luhn&amp;rft.appldate=1954-01-06&amp;rft.pubdate=1960-08-23"><span style="display: none;">&#160;</span></span></span> </li> <li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1215172403">.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("//upload.wikimedia.org/wikipedia/commons/6/65/Lock-green.svg")right 0.1em center/9px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a{background-size:contain}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("//upload.wikimedia.org/wikipedia/commons/d/d6/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a{background-size:contain}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("//upload.wikimedia.org/wikipedia/commons/a/aa/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a{background-size:contain}.mw-parser-output .cs1-ws-icon a{background:url("//upload.wikimedia.org/wikipedia/commons/4/4c/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:#d33}.mw-parser-output .cs1-visible-error{color:#d33}.mw-parser-output .cs1-maint{display:none;color:#2C882D;margin-left:0.3em}.mw-parser-output .cs1-format{font-size:95%}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911F}html.skin-theme-clientpref-night .mw-parser-output .cs1-visible-error,html.skin-theme-clientpref-night .mw-parser-output .cs1-hidden-error{color:#f8a397}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-visible-error,html.skin-theme-clientpref-os .mw-parser-output .cs1-hidden-error{color:#f8a397}html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911F}}</style><cite class="citation techreport cs1">"Annex B: Luhn formula for computing modulus-10 "double-add-double" check digits". <a rel="nofollow" class="external text" href="https://www.iso.org/standard/70484.html"><i>Identification cards — Identification of issuers — Part 1: Numbering system</i></a> (Standard). <a href="/wiki/International_Organization_for_Standardization" title="International Organization for Standardization">International Organization for Standardization</a>, <a href="/wiki/International_Electrotechnical_Commission" title="International Electrotechnical Commission">International Electrotechnical Commission</a>. January 2017. <a href="/wiki/ISO/IEC_7812" title="ISO/IEC 7812">ISO/IEC 7812</a>-1:2017.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=report&amp;rft.btitle=Identification+cards+%E2%80%94+Identification+of+issuers+%E2%80%94+Part+1%3A+Numbering+system&amp;rft.pub=International+Organization+for+Standardization%2C+International+Electrotechnical+Commission&amp;rft.date=2017-01&amp;rft_id=https%3A%2F%2Fwww.iso.org%2Fstandard%2F70484.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ALuhn+algorithm" class="Z3988"></span></span> </li> <li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1215172403"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://postalpro.usps.com/pub199">"Publication 199: Intelligent Mail Package Barcode (IMpb) Implementation Guide for Confirmation Services and Electronic Payment Systems"</a>. United States Postal Service<span class="reference-accessdate">. Retrieved <span class="nowrap">29 November</span> 2023</span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=unknown&amp;rft.btitle=Publication+199%3A+Intelligent+Mail+Package+Barcode+%28IMpb%29+Implementation+Guide+for+Confirmation+Services+and+Electronic+Payment+Systems&amp;rft.pub=United+States+Postal+Service&amp;rft_id=https%3A%2F%2Fpostalpro.usps.com%2Fpub199&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3ALuhn+algorithm" class="Z3988"></span></span> </li> </ol></div> <h2><span class="mw-headline" id="External_links">External links</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Luhn_algorithm&amp;action=edit&amp;section=11" title="Edit section&#039;s source code: External links"><span>edit source</span></a><span class="mw-editsection-bracket">]</span></span></h2> <ul><li><a rel="nofollow" class="external text" href="https://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers">Implementation in 150 languages on the Rosetta Code project</a></li></ul></div>'
Whether or not the change was made through a Tor exit node (tor_exit_node)
false
Unix timestamp of change (timestamp)
'1715249641'