FreeCalypso > hg > fc-sim-tools
comparison libutil/iccid_luhn.c @ 8:34bbb0585cab
libutil: import from previous fc-pcsc-tools version
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 05:42:37 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:b25d4dfe5798 | 8:34bbb0585cab |
---|---|
1 /* | |
2 * This module implements a function for computing the Luhn check digit | |
3 * for ICCIDs that follow the 18+1 convention. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 | |
8 compute_iccid_luhn(digits) | |
9 u_char *digits; | |
10 { | |
11 int i, dig, sum; | |
12 | |
13 sum = 0; | |
14 for (i = 0; i < 18; i++) { | |
15 dig = digits[i]; | |
16 if (i & 1) { | |
17 dig *= 2; | |
18 if (dig > 9) | |
19 dig -= 9; | |
20 } | |
21 sum += dig; | |
22 } | |
23 dig = sum % 10; | |
24 if (dig) | |
25 dig = 10 - dig; | |
26 return dig; | |
27 } |