I recently lost my mobile. I searched about how to lock the mobile. I found some pages like IMEI finder that are interesting. They validate the IMEI using the Luhn algorithm. An IMEI number has only 15 or 17 digits. The IMEI numbers N-1 digits are serial numbers, the last digit is a check digit. The IMEI number consists of a manufacturer identity number, distribution number, and other info.
Example
IMEI number |
3 |
5 |
7 |
8 |
0 |
5 |
0 |
2 |
3 |
9 |
8 |
4 |
9 |
4 |
? |
Double every other digit |
3 |
10 |
7 |
16 |
0 |
10 |
0 |
4 |
3 |
18 |
8 |
8 |
9 |
8 |
? |
Sum all digits |
3 + (1 + 0) + 7 + (1+6) + 0 + (1+0)+ 0 + 4 + 3 + (1+8) + 8 + 8 + 9 + 8 + ? = 68 |
Refer to: http://imei-number.com/check-digit-calculation/
Add all the odd digits and double the even digits and add the digits of the doubling value. Then finally add all the values. Now it has some value (here 68) so the final digit, the check digit, would come from the difference of the preceding total value and the nearest value of the nearest 10. Here the total is 68, the nearest 10 is 70, the difference is 2.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace IMEI_Number_Finder
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string imei = textBox1.Text.Trim();
string sub = "";
int total = 0;
int length = imei.Length - 1;
if (imei.Length == 15 || imei.Length == 17)
{
for (int i = 0; i < length; i++)
{
if (i % 2 != 0)
{
sub = ((int)char.GetNumericValue(imei[i]) * 2).ToString();
total += sub.Length == 2 ? (int)char.GetNumericValue(sub[0]) + (int)char.GetNumericValue(sub[1]) : (int)char.GetNumericValue(sub[0]);
}
else
total += ((int)char.GetNumericValue(imei[i]));
}
if ((int)char.GetNumericValue(imei[length]) == ((((total / 10) + 1) * 10) - total))
{
MessageBox.Show("Valid IMEI Number");
}
else
{
MessageBox.Show("In-Valid IMEI Number");
textBox1.Text = "";
sub = "";
total = 0;
length = 0;
}
}
else
{
MessageBox.Show("In-Valid IMEI Number");
textBox1.Text = "";
sub = "";
total = 0;
length = 0;
}
}
}
}
This is the last digit. This is the validation process of the IMEI.