Validate IMEI in Different Programming Languages (Delphi, C++, C#)

Hi Friends,
Our new topic is for verifying IMEIs with its checksum. Almost every person know the fact that IMEI number is using an algorithm that is called Luhn Algorithm in short form it is same like an checksum procedure. Some time we missed a digit from IMEI while we are writing it to phone and the whole IMEI is not working this is the main reason behind it the checksum.

So lets start our topic, and Firstly we do it into Delphi. as you all know I love Delphi. Here we go,

Borland Delphi



It is not quite difficult in Delphi just use this function that I posted below.

function IMEIChecksum(imei : string): string;
var
  a : Integer;
  sum : Integer;
  i : Integer;
  d : string;
  ds : Integer;
begin
  a := 0;
  sum := 0;
  for i := 0 to Length(imei)-1 do
  begin
    d := Copy(imei, Length(imei)-i, 1);
    ds := StrToInt(d);
    if a mod 2 = 0 then
      ds := ds * 2;
    if ds > 9 then
      ds := ds - 9;
    sum := sum + ds;
    a := a + 1;
  end;
  sum := sum mod 10;
  Result := IntToStr(10 - sum);
end;
Copy the above function and paste it into Delphi IDE. Call it through any button. as shown in picture.
This function requires only 14 digits of IMEI, the last digit will be generated and returned. You can use it to show IMEI in any editbox or memo.

Checksum Function

Button on click function

C++

Our second target is making Luhn Algorithm in C++. C++ is most famous language used by so many developers around the world. I have managed to create a same function like Delphi in C++. So the function is given below.
String IMEIChecksum(String g)
{
  String imei = g;
  int a = 0;
  int sum = 0;
  for(int i = 0; i < imei.Length(); i++)
  {
    int d = StrToInt(imei.SubString(imei.Length() - i, 1));
    if(a % 2 == 0)
      d = d * 2;
    if(d > 9)
      d -= 9;
    sum += d;
    a++;
  }
  int j = 10 - (sum % 10);
  return IntToStr(j);
}

I have coded this algorithm in Borland C++. It will work on every C++ compiler. Check this and post your feedback in comment section. 

Microsoft Visual C#

Our third target is to create the same function in C#. It is same as C++ but somethings are changed in C#. It is quite easy for me to create function same like Delphi in C#. I used Microsoft Visual C# 2010. So the function is given below.
public static string IMEIChecksum(string imei)
{
int a = 0;
int sum = 0;
for (int i = 0; i < imei.Length; i++)
  {
    int d = Convert.ToInt32(imei.Substring(imei.Length - 1 - i, 1));
    if (a % 2 == 0)
        d = d * 2;
    if (d > 9)
        d -= 9;
    sum += d;
    a++;
  }
int j = 10 - (sum % 10);
return j.ToString();
}

It is the last compiler that I use. You can also clone these function to create the same function in Python, PHP and Java. But these languages are difficult for me as I am not started working on them.

Hope these functions will work good on your projects. This is just for fun purpose don't use it for doing any illegal work. I am not responsible for any illegal work done by these functions.

Regards,
GautamGreat
CrackingGSM Team 
SHARE

Author

Hi, Its me GautamGreat. A Reverser, Programmer and a developer. Developed a lot of programs. Cracking is my hobby I' am student of Class 12th, Who has a mobile phones repairing office. A blogger from heart and a student from mind.

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment