forked from vishnupoothery/misc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyGen.py
More file actions
52 lines (46 loc) · 1.29 KB
/
keyGen.py
File metadata and controls
52 lines (46 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import random
class Key:
def __init__(self,key=''):
if(key==''):
self.key=self.generate()
else:
self.key=key.lower()
def generate(self):
key = ''
chunk=''
alphabets = 'abcdefghijklmnopqrstuvwxyz1234567890'
while True:
while len(key) < 25 :
char = random.choice(alphabets)
key += char
chunk+=char
if len(chunk) == 4:
key+='-'
chunk=''
key = key[:-1]
if Key(key).verify():
return key
else:
key=''
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 > 1770 and check_digit_count == score%6:
return True
return False
def __str__(self):
valid = 'Invalid'
if self.verify():
valid = 'Valid'
return self.key.upper()+' '+valid
key=Key()
print(key)