Last active
April 12, 2024 08:51
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
tac 35582008
TAC CODE;35490110
TAC: 35455037
35455037
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tac 35582008