IMEI modification (calculation of IMEI 15th-bit verification code)

Source: Internet
Author: User

Recently, the IMEI modification function was implemented at the customer's request, so I carefully learned the IMEI orchestration rules and how to calculate the IMEI:

1,What is IMEI?
IMEI is TAC + FAC + SNR + sp. IMEI (International Mobile Equipment Identity) is the abbreviation of international mobile device identity code. It is an "electronic serial number" consisting of 15 digits ", it corresponds to each mobile phone, and the code is the only one in the world. Each mobile phone is assigned a unique group of numbers in the world after it is assembled. This number will be recorded by the manufacturer who manufactures it from production to delivery.

It consists:
1. The first six digits (TAC) are "model approval numbers", which generally represent models.
2. The next two digits (FAC) are the "last Assembly number", which generally represents the origin.
3. the next 6 digits (SNR) are "serial numbers", which generally represent the production sequence numbers.
4. the last 1-digit (SP) is usually "0", which is the Verification Code and is currently in use.
The IMEI code is attached to the logo on the back of the mobile phone and is read and written to the memory of the mobile phone. It is also the "file" and "ID card number" of the mobile phone in the manufacturer ".
------ TAC ------------ -- fac------- SNR -----------
D14 D13 D12 D11 D10 D9 D7 D6 D5 D4 D3 D2 D1 D0
3 5 3 1 1 4 0 0 8 0 9 6 3 6 6
To calculate the IMEI verification code, follow these steps:
1. Set the odd number of IMEI digits to * 2, for example, D1, D3, D5 ,...... D13
D13 D11 D9 D7 D5 D3 d1
10 2 8 0 0 12 12
2. Add the seven odd digits to a single digit (if a two digit is obtained, the ten digits and the single digit are regarded as single digits respectively ), add seven even-digit numbers, such as D2, D4, D6 ...... D14
3 + 1 + 0 + 3 + 2 + 1 + 8 + 0 + 0 + 8 + 0 + 9 + 1 + 2 + 3 + 1 + 2 = 44
3. If the last digit of step 1 is 0, the number of the verification code is 0. If the number of digits at the end of step 1 is not 0, the result of the calculation is greater than the double-digit integer ending with 0 in step 2, minus the result of step 2. The obtained single-digit is the verification code.
D0 = 50-44 = 6

2,The luhn file written by myself is attached below.Algorithm

/*************************************** **************************************** * *** Function Name: cgibase_autochangeimeide.pdf: pass in a 14-bit IMEI value, calculate the 15th-bit calibration code, and return the 15-bit IMEI value Author: zhou Ying ************************************** **************************************** * ***/unsigned long cgibase_autochangeimei (char * pcsource, char * pcdest) {int I, j, k; int itotal, ieventotal, iaddtotal, itemp, iauth; char aceve N [10], acadd [10], actemp [3], acauth [2]; If (null = pcsource) | (null = pcdest )) {return 1;} memset (aceven, 0x0, sizeof (aceven); memset (acadd, 0x0, sizeof (acadd); j = 0; k = 0; itemp = 0; ieventotal = 0; iaddtotal = 0; itotal = 0; iauth = 0; for (I = 0; I <14; I ++) {If (0 = (I % 2) {aceven [J] = * (pcsource + I); memset (actemp, 0x0, sizeof (actemp )); sprintf (actemp, "% C", aceven [J]); itemp = atoi (actemp); IE Ventotal + = itemp; j + = 1;} else {acadd [k] = * (pcsource + I); memset (actemp, 0x0, sizeof (actemp )); sprintf (actemp, "% C", acadd [k]); itemp = atoi (actemp) * 2; iaddtotal + = (itemp/10) + (itemp % 10 ); K + = 1 ;}}itotal = ieventotal + iaddtotal; If (itotal >=100) {iauth = itotal % 100% 10; If (iauth! = 0) {iauth = (itotal % 100)/10 + 1) * 10-itotal % 100;} else {iauth = itotal % 10; If (iauth! = 0) {iauth = (itotal/10 + 1) * 10-itotal;} memset (acauth, 0x0, sizeof (acauth); sprintf (acauth, "% d", iauth); strcat (pcdest, pcsource); strcat (pcdest, acauth); Return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.