Created
March 4, 2014 01:19
-
-
Save globby/9338384 to your computer and use it in GitHub Desktop.
A slightly confusing implementation of the Verhoeff algorithm
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
def verhoeff(string): | |
string, c = list(string)[::-1], 0 | |
d, p, inv = map(lambda x:(lambda f,s:[map(int,list(f[i:i+s])) for i in range(0,len(f),s)])("0"+str(int(x,32)),10), | |
["1pphkblhcil6aq7anvo920aj7hpi14o8nu4t71vvat8a270c2avapk1868t7300dna", | |
"labkl84c4rp10j7aqnspj1hi8k79r7o790ac4n72ok70e8uale7a", | |
"cs4c3l"]) | |
for i, v in enumerate(string): | |
c = d[c][p[i%8][int(v)]] | |
return c == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment