Skip to content

Instantly share code, notes, and snippets.

@howCodeORG
Created May 22, 2018 01:28
Show Gist options
  • Save howCodeORG/4b456d334a85b516c0860b7495ff9d18 to your computer and use it in GitHub Desktop.
Save howCodeORG/4b456d334a85b516c0860b7495ff9d18 to your computer and use it in GitHub Desktop.
howCode's simple key generation script in Python.
import random
class Key:
def __init__(self, key=''):
if key == '':
self.key= self.generate()
else:
self.key = key.lower()
def verify(self):
score = 0
check_digit = self.key[0]
check_digit_count = 0
chunks = self.key.split('-')
for chunk in chunks:
if len(chunk) != 4:
return False
for char in chunk:
if char == check_digit:
check_digit_count += 1
score += ord(char)
if score == 1772 and check_digit_count == 5:
return True
return False
def generate(self):
key = ''
chunk = ''
check_digit_count = 0
alphabet = 'abcdefghijklmnopqrstuvwxyz1234567890'
while True:
while len(key) < 25:
char = random.choice(alphabet)
key += char
chunk += char
if len(chunk) == 4:
key += '-'
chunk = ''
key = key[:-1]
if Key(key).verify():
return key
else:
key = ''
def __str__(self):
valid = 'Invalid'
if self.verify():
valid = 'Valid'
return self.key.upper() + ':' + valid
@QuickMuffin87822
Copy link

QuickMuffin87822 commented Nov 14, 2020

Woah. That's gotta be good to use.

@adumbwest
Copy link

steals code XD

@Xotique
Copy link

Xotique commented Jul 11, 2021

i wanted to be able to create this key gen by myself so i decided to check this source code out but i just can't understand somethings here.

@vincent020
Copy link

is it only me that only can see until line 50 or same goes to everyone else?

@Kipngetich33
Copy link

@vincent020 I believe that is the last line of the file

@Johnwaithz
Copy link

When I run this script it returns nothing.

@JakeK34959
Copy link

@Johnwaithz at the end out side of the key class add this line

print(Key())

@Sibilanc
Copy link

I still have a blank output.

@Sibilanc
Copy link

Wait never mind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment