Monday, 28 October 2013

IMEI Number and Check digit Algorithm

This purpose of this article is used to explain the IMEI Number and Check digit Algorithm which is  normally added as last digit in the IMEI number.

what is IMEI ?
                International Mobile Equipment Identity used to identify the mobile phones and some of the satellite phones. IMEI number is normally present in the box of the phone. To Use the IMEI number by typing *#06# or *#0000# on some phones. The IMEI number is used by rthe GSM network to identify a valid device.

What is Check digit ?
      Check digit is present in the Last of the IMEI number it is generated based on LUHN 's Algorithm, To check a Valid Device. This algorithm is invented by an IBM scientist.

Algorithm :

IMEI : 256533912774352

1. Start from the right double every second digit.
2. Add the second digit if it gives double digit on multiply
3. Now add all number and modulus with 10 , If remaining present other than 0 minus with 10 result value is check digit otherwise 0 is check digit.





Program in c#:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Is Valid IMEI " + IsValidIMEI("256533912774354"));
            Console.Read();
        }

        static bool IsValidIMEI(string imei)
        {
            int []n=new int[imei.Length];
            for (int i = 0; i < imei.Length; i++)
            {
                n[i] =  int.Parse(imei[i].ToString());
            }

            for(int i=0;i<imei.Length-1;i++)
            {
                if(i %2==1)
                {
                    n[i] = n[i]*2;
                }
            }

            for(int i=0;i<imei.Length-1;i++)
            {
                if(i %2==1)
                {
                    if(n[i].ToString().Length>1)
                    n[i] = int.Parse(n[i].ToString()[0].ToString()) + int.Parse(n[i].ToString()[1].ToString());
                }
            }
            
            int total=0;
            for(int i=0;i<imei.Length-1;i++)
            {
             total+=n[i];  
            }

            int mod = total %10;

            if(mod>0)
            {
                mod=10-mod;
            }
        
        return (n[imei.Length-1]==mod);
        }

    }
}




Output : 

ISValid IMEI : True


From this article , you will learn what is the algorithm use to calculate the check digit.


1 comment:

  1. Search IMEI is here to assist you to find your lost mobile. You just need to register your mobile phone's unique imei number.


    For more info : check imei

    ReplyDelete