Skip to content

Instantly share code, notes, and snippets.

@artem78
Created June 10, 2026 09:27
Show Gist options
  • Select an option

  • Save artem78/6d3fd53973944e4852460ad31cee9f3d to your computer and use it in GitHub Desktop.

Select an option

Save artem78/6d3fd53973944e4852460ad31cee9f3d to your computer and use it in GitHub Desktop.
simple key generator example in python
#!/usr/bin/python3
import re
import hashlib
import random
import argparse
def validateKey(k):
k = k.strip()
k = k.upper()
pattern = re.compile("^[A-Z0-9]{16}$")
# if found match (entire string matches pattern)
if pattern.fullmatch(k) is None:
return False
h = hashlib.md5(k.encode())
h = h.hexdigest().lower()
h2 = hashlib.md5(h.encode())
h2 = h2.hexdigest().lower()
h3 = hashlib.md5(h2.encode())
h3 = h3.hexdigest().lower()
#print(h, h2, h3)
return h3[-2] + h3[-1] == '57' and h[0] == 'a' and h2[7] == 'b' and h[-10] == 'd' #and h2[9] == '9'
def generateKey():
alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
j=0
while 1:
j+=1
k=''
for i in range(16):
k += random.choice(alphabet)
res = validateKey(k)
#print(j, k, res)
if res:
#print('iterations:', j, 'key:', k)
return k
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--count', default=1, type=int)
args = parser.parse_args()
for i in range(args.count):
print(generateKey())
# usage:
#
# $ python3 keygen.py
# 0EH1KRR2A9JXK6LB
#
# $ python3 keygen.py -c 3
# ELIFO96SCI7YVAI9
# V6WIV1J6IT21MU6U
# CMSZSNHZ3ZTBBXF5
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment