Skip to content

Instantly share code, notes, and snippets.

@righthandabacus
Created February 16, 2018 03:51
Show Gist options
  • Save righthandabacus/ea83fbb6cf139fe6468f1d8e626d320f to your computer and use it in GitHub Desktop.
Save righthandabacus/ea83fbb6cf139fe6468f1d8e626d320f to your computer and use it in GitHub Desktop.
Generate rainbow table for all HKID: To prove hashing HKID is not a security measure
from __future__ import print_function
import itertools
import hashlib
# generate a rainbow table for HKID
# 2017-02-11
def checkdigit(a, i, j, k, l, m, n):
numeric = [ord(a) - 65 + 1, int(i), int(j), int(k), int(l), int(m), int(n)]
weight = range(8,1,-1)
product = sum(n*w for n,w in zip(numeric, weight))
rem = 11 - (product % 11)
return 'A' if rem == 10 else str(rem)
alpha = [chr(o) for o in range(65, 91)]
digit = [str(x) for x in range(10)]
with open('hkid-rainbow.txt', 'wa') as f:
for a, i, j, k, l, m, n in itertools.product(alpha, digit, digit, digit, digit, digit, digit):
x = checkdigit(a, i, j, k, l, m, n)
hkid = ''.join([a, i, j, k, l, m, n, '(', x, ')'])
print(hashlib.sha512(hkid).hexdigest(), file=f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment