Personalizing test (U)SIM cards for different customers, a new challenge arose where a customer actually wanted different serial numbers on the cards. Our test cards have the same ICCID number on all cards. Anyway, this is handled by the file 2F E2 - IC Card Identifier, under MF. This file contains the IC card's serial number coded on 10 bytes and allows the operator to identify the card unambiguously for billing purposes.
The coding of the serial number for cards of Phase2/2+ onwards it is defined in ITU-T E118. CCITT E118 specifies a Serial Number length between 0 and 18 digits plus an extra byte containing a checksum written in its least significant (that is, rightmost) digit. The checksum is always stored in this byte whatever the length of the serial number (if the serial number is shorter than 18 digits it is padded (One or more bits appended to a message in order to ensure that it contains the required number of bits or bytes.) with Fh up to digit 20. Coding the serial number on 20 digits overwrites the checksum. Some operators today use 19 digits followed by the checksum without any padding.
It's composed of the following subparts:
– Major Industry Identifier (MII);
– country code;
– issuer identifier;
– individual account identification number;
– parity check digit
Now, using a tool like Gemalto Card Admin I can automatically get the correct checksum for the ICCID I choose to enter. But in our automated processes where we use APDU scripts, I needed to know how to calculate this checksum so it could be automatically appended to the serial number and the card correctly personalised.
I found out that the Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm, is used to calculate the checksum.
So very simply, assume an example of a serial number "896588081210001114" that will have a check digit added, making it of the form 896588081210001114x:
|Double every other||8||18||6||10||8||16||0||16||1||4||1||0||0||0||1||2||1||8|
|example: 18=>8+1=9||8||9||6||1||8||7||0||7||1||4||1||0||0||0||1||2||1||8||Sum of digits= 64|
First double every other number starting from the end. Add the digits if >1. For example 18=1+8=9
The check digit (x) is obtained by computing the sum of digits then computing 9 times that value modulo 10 (so that's: (67 * 9 mod 10)). In layman's terms:
So in this case the complete ICCID is 8965880812100011146
Created : 2016-04-29 10:13:06, Last Modified : 2017-06-14 14:53:31