Last active
August 29, 2015 14:02
-
-
Save ph87/d9e44129b701e5a0f230 to your computer and use it in GitHub Desktop.
Sum Check Schema for IOS 7064 Mod 11-2 (Unique Identifier for People, People's Republic of China)
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
code = '12346830281720938x' # check sum equal 10, maped to 'x' | |
sum = 0 | |
for i in code[:-1]: | |
sum = ( sum + int(i, 10)) * 2 | |
sum_mod = sum % 11 | |
sum_check = (12 - sum_mod ) % 11 | |
sum_check = 'x' if sum_check == 10 else str(sum_check) | |
assert sum_check == code[-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment