Skip to content

Commit 309fb30

Browse files
committed
Add new category utility
1 parent 9270ca6 commit 309fb30

File tree

1 file changed

+59
-0
lines changed
  • Utility_scripts/src/key_generator

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import random
2+
3+
4+
class Key:
5+
6+
def __init__(self, key=''):
7+
if key == '':
8+
self.key = self.generate()
9+
else:
10+
self.key = key.lower()
11+
12+
def verify(self):
13+
score = 0
14+
check_digit = self.key[0]
15+
check_digit_count = 0
16+
chunks = self.key.split('-')
17+
for chunk in chunks:
18+
if len(chunk) != 4:
19+
return False
20+
for char in chunk:
21+
if char == check_digit:
22+
check_digit_count += 1
23+
score += ord(char)
24+
if score == 1772 and check_digit_count == 5:
25+
return True
26+
return False
27+
28+
def generate(self):
29+
key = ''
30+
chunk = ''
31+
check_digit_count = 0
32+
alphabet = 'abcdefghijklmnopqrstuvwxyz1234567890'
33+
while True:
34+
while len(key) < 25:
35+
char = random.choice(alphabet)
36+
key += char
37+
chunk += char
38+
if len(chunk) == 4:
39+
key += '-'
40+
chunk = ''
41+
key = key[:-1]
42+
if Key(key).verify():
43+
return key
44+
else:
45+
key = ''
46+
47+
def __str__(self):
48+
valid = 'Invalid'
49+
if self.verify():
50+
valid = 'Valid'
51+
return self.key.upper() + ':' + valid
52+
53+
54+
def main():
55+
generated_key = Key()
56+
print(generated_key)
57+
58+
if __name__ == "__main__":
59+
main()

0 commit comments

Comments
 (0)