Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephTLyons committed Mar 27, 2020
1 parent 9ce5a35 commit d9bb8f5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ License separator character (keep blank for newline):
License Characteristics Options
===============================
License number length: 20
License length: 20
Enter 'y' to use numbers: y
Enter 'y' to use uppercase letters: y
Enter 'y' to use lowercase letters: y
Expand All @@ -34,8 +34,8 @@ Enter 'y' to use symbols: n
Results
=======
File path: /Users/josephlyons/Programming/Python/andromeda/src/1000_unique_licenses.txt
Requested license number amount: 1000
Total possible license numbers given current inputs: 62^20 = 704423425546998022968330264616370176
Requested number of licenses: 1000
Total possible number of licenses given current inputs: 62^20 = 704423425546998022968330264616370176
License pool coverage: (1000 / (62^20)) * 100 = 1.4196007170310687e-31%
```

Expand Down Expand Up @@ -64,10 +64,10 @@ dFheZibfSFeXVlPfzeSg

## How it Works
1. Check to make sure that it is possible to create the amount of unique
licenses requested based on the the license number length and character set.
For example, if the user requests `1,000,000` unique licenses, but only asks
for licenses of length `4` and wants only numbers as characters, it will not
be possible, as `10^4 < 1,000,000`. We must have more possible combinations
licenses requested based on the the license length and character set. For
example, if the user requests `1,000,000` unique licenses, but only asks for
licenses of length `4` and wants only numbers as characters, it will not be
possible, as `10^4 < 1,000,000`. We must have more possible combinations
than the number of licenses requested in order to ensure all licenses will be
unique.
2. Make a `characterList` that is comprised of all the symbols the user wishes
Expand Down Expand Up @@ -168,7 +168,7 @@ License separator character (keep blank for newline):
License Characteristics Options
===============================
License number length: 4
License length: 4
Enter 'y' to use numbers: y
Enter 'y' to use uppercase letters: n
Enter 'y' to use lowercase letters: n
Expand All @@ -177,8 +177,8 @@ Enter 'y' to use symbols: n
Results
=======
File path: /Users/josephlyons/Programming/Python/andromeda/src/1000_unique_licenses.txt
Requested license number amount: 1000
Total possible license numbers given current inputs: 10^4 = 10000
Requested number of licenses: 1000
Total possible number of licenses given current inputs: 10^4 = 10000
License pool coverage: (1000 / (10^4)) * 100 = 10.0%
```

Expand Down Expand Up @@ -208,6 +208,6 @@ Notice that the licenses are fairly similar. Also, note that it would be fairly
easy to guess a license. The probability that a random guess would be an actual
license is `1000/(10^4) = 0.1`. It is up to the user to understand this and
adjust the settings to increase the complexity of the output and decrease the
chances of guessing a license number. Using the example from earlier with
`1000` licenses of length `20` using all symbols, the probability that a random
guess would be an actual license is `1000/(62^20) = 1.4196007e-33`.
chances of guessing a license. Using the example from earlier with `1000`
licenses of length `20` using all symbols, the probability that a random guess
would be an actual license is `1000/(62^20) = 1.4196007e-33`.
28 changes: 14 additions & 14 deletions src/license_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def __init__(self, file_options_dict, batch_license_dict, license_characteristic
self.index_list = IndexList(self.license_characteristics_dict["length"],
self.license_characteristics_dict["number_of_characters"])

self.file_name = str(self.batch_license_dict["number_or_licenses"]) \
self.file_name = str(self.batch_license_dict["number_of_licenses"]) \
+ "_unique_licenses" \
+ "." \
+ self.file_options_dict["file_extension"]

def generate(self):
if (self.license_characteristics_dict["total_possible_licenses"] < self.batch_license_dict["number_or_licenses"]):
if (self.license_characteristics_dict["total_possible_licenses"] < self.batch_license_dict["number_of_licenses"]):
self.__print_error_message()
return

Expand All @@ -38,7 +38,7 @@ def __create_list_of_character_lists(self):
return list_of_character_lists

def __print_error_message(self):
print("Requested license number amount: {}".format(self.batch_license_dict["number_or_licenses"]))
print("Requested number of licenses: {}".format(self.batch_license_dict["number_of_licenses"]))
print("Total possible licenses given current inputs: ", end='')
print(self.license_characteristics_dict["total_possible_licenses"])
print("Try one or more of the following:")
Expand All @@ -47,11 +47,11 @@ def __print_error_message(self):
print("- Decreasing the amount of licenses to be generated")

def __print_licenses_to_file(self):
with open(self.file_name, "w") as serial_file:
with open(self.file_name, "w") as license_file:
single_license_string = ""
distance_between_licenses = self.license_characteristics_dict["total_possible_licenses"] // self.batch_license_dict["number_or_licenses"]
distance_between_licenses = self.license_characteristics_dict["total_possible_licenses"] // self.batch_license_dict["number_of_licenses"]

for i in range(self.batch_license_dict["number_or_licenses"]):
for i in range(self.batch_license_dict["number_of_licenses"]):
for j in range(self.license_characteristics_dict["length"]):
single_license_string += self.list_of_character_lists[j][self.index_list.at(j)]

Expand All @@ -61,10 +61,10 @@ def __print_licenses_to_file(self):
if self.index_list.has_overflowed:
raise ValueError("Index List has overflowed.")

if i < self.batch_license_dict["number_or_licenses"] - 1:
if i < self.batch_license_dict["number_of_licenses"] - 1:
single_license_string += self.batch_license_dict["license_separator_character"]

serial_file.write(single_license_string)
license_file.write(single_license_string)
single_license_string = ""

# print(self.index_list.get_index_string())
Expand All @@ -75,15 +75,15 @@ def __print_path_to_terminal(self):
print("File path: {}".format(file_path))

def __print_stats_to_terminal(self):
self.__print_number_or_licenses()
self.__print_number_of_licenses()
self.__print_total_possible_licenses()
self.__print_percent_of_license_pool_covered()

def __print_number_or_licenses(self):
print("Requested license number amount: " + str(self.batch_license_dict["number_or_licenses"]))
def __print_number_of_licenses(self):
print("Requested number of licenses: " + str(self.batch_license_dict["number_of_licenses"]))

def __print_total_possible_licenses(self):
print("Total possible license numbers given current inputs: ", end='')
print("Total possible number of licenses given current inputs: ", end='')
print(self.license_characteristics_dict["number_of_characters"], end='')
print("^", end='')
print(self.license_characteristics_dict["length"], end='')
Expand All @@ -92,10 +92,10 @@ def __print_total_possible_licenses(self):

def __print_percent_of_license_pool_covered(self):
print("License pool coverage: (", end='')
print(str(self.batch_license_dict["number_or_licenses"]) + " / ", end='')
print(str(self.batch_license_dict["number_of_licenses"]) + " / ", end='')
print("(" + str(self.license_characteristics_dict["number_of_characters"]), end='')
print("^", end='')
print(str(self.license_characteristics_dict["length"]) + ")) * 100 = ", end='')
print(((self.batch_license_dict["number_or_licenses"] /
print(((self.batch_license_dict["number_of_licenses"] /
self.license_characteristics_dict["total_possible_licenses"]) * 100), end='')
print("%")
6 changes: 3 additions & 3 deletions src/options_dictionaries.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from string import ascii_lowercase, ascii_uppercase, digits, punctuation

def get_batch_license_dict():
number_or_licenses = int(input("Number of licenses: "))
number_of_licenses = int(input("Number of licenses: "))

license_separator_character = ""

Expand All @@ -15,7 +15,7 @@ def get_batch_license_dict():
license_separator_character = "\n"

batch_license_dict = {
"number_or_licenses": number_or_licenses,
"number_of_licenses": number_of_licenses,
"license_separator_character": license_separator_character,
}

Expand All @@ -34,7 +34,7 @@ def get_file_options_dict():
return file_options_dict

def get_license_characteristics_dict(license_separation_character):
length = int(input("License number length: "))
length = int(input("License length: "))
character_list = __create_character_list()

if license_separation_character != "\n" and license_separation_character in character_list:
Expand Down

0 comments on commit d9bb8f5

Please sign in to comment.