Created
February 5, 2014 03:45
-
-
Save isayme/8817134 to your computer and use it in GitHub Desktop.
id check python script,
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/python | |
# -*- coding: utf-8 -*- | |
import re; | |
# id check function | |
def IC_chk(ic_serial): | |
# value array | |
iW = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1]; | |
# characters in ID | |
values = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'x'] | |
# reg | |
icre = re.compile('^[1-9][0-9]{16}[x0-9]$', re.IGNORECASE); | |
m = icre.match(ic_serial); | |
if m: | |
pass; | |
else: | |
# if not valid, return | |
return False; | |
S = 0; | |
for i in range(0,17): | |
S += int(ic[i]) * iW[i]; | |
chk_val = (12 - (S % 11)) % 11; | |
print values[chk_val]; | |
return ic_serial[17].lower() == values[chk_val]; | |
if __name__ == '__main__': | |
# test case | |
ic = raw_input("Please input IC serial: "); | |
if IC_chk(ic): | |
print "Correct IC Serial!"; | |
else: | |
print "Wrong IC Serial!"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment