Sign in Join
Wiki copytemporary

Luhn algorithm/fr: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Luhn algorithm/fr

OldNewLine
1+Cet algorithme a été créé par Hans Peter Luhn. Il est spécifié dans la norme [ISO/IEC 7812-1](https://en.wikipedia.org/wiki/ISO/IEC_7812) et est utilisé par certaines cartes de crédit par exemple.
2+
3+``` pascal
4+function LuhnAlgorithmCheckDigit(const s:string):integer;
5+var
6+ l, i, sum, deo : integer;
7+begin
8+ l := length( s );
9+ sum := 0;
10+ for i := l downto 1 do
11+ begin
12+ if odd(i) then sum := sum + StrToInt(s[i])
13+ else
14+ begin
15+ deo := StrToInt(s[i]) * 2 ;
16+ if deo > 9 then deo := deo mod 10 + 1;
17+ sum := sum + deo;
18+ end;
19+ end;
20+ result := 10 - sum mod 10;
21+end;
22+
23+function isLuhnValid( const s : string ): boolean;
24+var
25+ i, l :integer;
26+begin
27+ l := length( s );
28+ i := LuhnAlgorithmCheckDigit( copy( s, 1, l-1) );
29+ result := i = StrToInt( s[ l ] );
30+end;
31+```
32+
33+---
34+*From the Free Pascal wiki, page "Luhn algorithm/fr", as it stood on 2020-02-19 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history