Skip to content

Instantly share code, notes, and snippets.

@isayme
Created February 5, 2014 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isayme/8817134 to your computer and use it in GitHub Desktop.
Save isayme/8817134 to your computer and use it in GitHub Desktop.
id check python script,
#!/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