Created
April 29, 2015 10:12
-
-
Save sgezel/5dab7469c5a247b3a382 to your computer and use it in GitHub Desktop.
CD-key generator & validator based on username
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
__author__ = 'sage' | |
def main(): | |
print('________________') | |
print('CD key generator') | |
print('________________') | |
print('') | |
username = input('Username? ') | |
numberofkeys = input('How many keys? ') | |
generate(username, int(numberofkeys)) | |
def generate(username, numberofkeys): | |
total = 0 | |
for letter in username.lower(): | |
total += ord(letter)*1.03 | |
gemiddeldeusername = round(total/username.__len__(), 0) | |
print('') | |
for index in range(0, numberofkeys): | |
average = 0 | |
cdkey = '' | |
for i in range(0, 5): | |
while gemiddeldeusername != average: | |
first = random.randrange(97, 97 + 26) | |
second = random.randrange(97, 97 + 26) | |
third = random.randrange(97, 97 + 26) | |
fourth = random.randrange(97, 97 + 26) | |
fifth = random.randrange(97, 97 + 26) | |
average = (first+second+third+fourth+fifth)/5 | |
average = 0 | |
if i != 0: | |
cdkey += '-' | |
cdkey = cdkey+chr(first) + chr(second)+chr(third)+chr(fourth)+chr(fifth) | |
print(cdkey) | |
cdkey='' | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'sage' | |
class Security: | |
def checkkey(self, username, cdkey): | |
total = 0 | |
for letter in username.lower(): | |
total += ord(letter)*1.03 | |
gemiddeldeUsername = round(total/username.__len__(), 0) | |
for piece in cdkey.split('-'): | |
totalpiece = 0 | |
for letter in piece: | |
totalpiece += ord(letter) | |
if totalpiece/piece.__len__() != gemiddeldeUsername: | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment