Created
May 8, 2017 10:40
-
-
Save khsing/25cf1822cd1c6d3321e32ee31702ef95 to your computer and use it in GitHub Desktop.
Convert IMEI-SV to 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
# -*- coding: utf-8 -*- | |
# @Author: khsing | |
# @Date: 2017-05-08 17:52:55 | |
# @Last Modified by: khsing | |
# @Last Modified time: 2017-05-08 18:38:08 | |
import sys | |
import hashlib | |
def checkImeisv(imeisv): | |
return len(imeisv) == 16 | |
def doubleOther(i): | |
x = i[0] | |
y = i[1] | |
if (x%2) == 0: | |
return str(int(y)*2) | |
else: | |
return y | |
def convert(imeisv): | |
_imei = imeisv[:-2] | |
imei = map(doubleOther, enumerate(reversed(_imei))) | |
checknum = 10 - (sum([int(i) for i in ''.join(reversed(imei))])%10) | |
if checknum == 10: | |
checknum = 0 | |
return _imei + str(checknum), checknum | |
def main(): | |
with open(sys.argv[1]) as fd: | |
for line in fd: | |
line = line.strip() | |
if checkImeisv(line): | |
print(hashlib.md5(convert(line)[0]).hexdigest()) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does not work :(