diff --git a/README.md b/README.md index 0061f129..07b151bc 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ ScriptsDump is a complete repository of all kind of scripts we and you can think - **[Graph Algorithms](/Graph_Algorithms/src)** +- **[Utility Scripts](/Utility_scripts/src)** + ## Maintainers diff --git a/Utility_scripts/src/key_generator/key_g.py b/Utility_scripts/src/key_generator/key_g.py new file mode 100644 index 00000000..f56b5371 --- /dev/null +++ b/Utility_scripts/src/key_generator/key_g.py @@ -0,0 +1,59 @@ +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 + + +def main(): + generated_key = Key() + print(generated_key) + +if __name__ == "__main__": + main()