Skip to content

Instantly share code, notes, and snippets.

@kamermans
Last active April 12, 2024 08:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kamermans/9f6fd1f575a11a18a9a970a17b7908ea to your computer and use it in GitHub Desktop.
Save kamermans/9f6fd1f575a11a18a9a970a17b7908ea to your computer and use it in GitHub Desktop.
Generates a complete, valid IMEI from a TAC code or otherwise incomplete IMEI.
#!/usr/bin/env python2
from random import randint
def generate_imei(incomplete_imei):
luhn_sum = 0
imei_digits = []
for i in xrange(0,14):
# Pull each digit from the TAC, generate missing numbers with rand()
try:
digit = incomplete_imei[i]
except IndexError:
digit = randint(0, 9)
# Add digits to IMEI
imei_digits.append(str(digit))
# Double every odd indexed digit
if (i % 2 != 0):
digit = digit * 2
# Split digits and add, ex: "14" becomes "1+4"
for component in str(digit):
luhn_sum = luhn_sum + int(component)
remainder = luhn_sum % 10
check_digit = 0 if (remainder == 0) else (10 - remainder)
imei_digits.append(str(check_digit))
return "".join(imei_digits)
#tac = "10457816123456"
#tac = "49015420323751"
tac = "104578"
imei = generate_imei(tac)
print("TAC: %s" % tac)
print("IMEI: %s" % imei)
@fiddle1999
Copy link

tac 35582008

@fiddle1999
Copy link

tac 35582008

@najimu24
Copy link

TAC CODE;35490110

@brytoctain
Copy link

TAC: 35455037

@adebayo0437
Copy link

35455037

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment