Created
January 25, 2013 18:17
-
-
Save hschmitt/4636628 to your computer and use it in GitHub Desktop.
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 | |
import sys | |
def product_key(): | |
all_keys = [] | |
#Check Arguments | |
if len(sys.argv) == 2: | |
total_keys = int(sys.argv[1]) | |
else: | |
print "Esta funcion requiere como 1 argumento" | |
return 0 | |
for key in range(total_keys): | |
current_key = None | |
while not current_key and current_key not in all_keys: | |
current_key = generate_key() | |
all_keys.append(current_key) | |
for key in all_keys: | |
print key | |
def generate_key(): | |
groups, length = 5,5 | |
generated_key = [] | |
for group in range(groups): | |
temp = '' | |
for digit in range(length): | |
temp += return_char(random.randint(1,15)) | |
generated_key.append(temp) | |
return '-'.join(generated_key) | |
def return_char(digit): | |
if digit < 10 : | |
return str(digit) | |
elif digit < 16: | |
return chr(64 + digit - 9) | |
else: | |
return '0' | |
if __name__ == "__main__": | |
product_key() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment