From 8981dd5f415f36c7ebffdcc3a44cb80f8515835b Mon Sep 17 00:00:00 2001 From: Castorp Date: Sat, 16 Mar 2019 02:55:36 +0000 Subject: [PATCH 1/9] Update passgen.py --- passgen.py | 234 ++++++++++++++++++++++++++--------------------------- 1 file changed, 113 insertions(+), 121 deletions(-) diff --git a/passgen.py b/passgen.py index 1660022..df1d2e2 100644 --- a/passgen.py +++ b/passgen.py @@ -2,141 +2,133 @@ # Author: Mohamed # Description: A password generator +from time import time + + +def is_integer(input_string): + integer_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] + for char in input_string: + if char not in integer_list: + return False + return True + + +def is_birthday(input_string): + if len(input_string) != 10: + return False + + if input_string.count('-') != 2: + return False + + if not is_integer(input_string.replace('-', '')): + return False + + return True + + +def cases(input_string): + return [input_string.lower(), input_string.title(), input_string.upper()] + class PassGen: def __init__(self): - self.pet = None - self.child = None - self.spouse = None - self.target = None self.passwords = [] - - def prompt(self, txt): - return str(input(txt)) + self.keywords_words = [] + self.keywords_words_cases = [] + self.keywords_integer = [] + self.keywords_birthday = [] + self.passwords = set() + + def chain_cases(self, case_list, i=0, input_combination=''): + for case in case_list[i]: + combination = input_combination + case + if len(case_list) == (i + 1): + self.keywords_words_cases.append(combination) + else: + self.chain_cases(case_list, i=i + 1, input_combination=combination) + + def collect_keywords(self): + + print('\n' + ' Please enter keywords associated with the target, e.g. names, numbers, birthdays;\n' + ' Birthdays have to have the following format: mm-dd-yyyy;\n' + ' After entering all your keywords, press CTRL + C to generate the password list;\n') - def question(self, target): - answers = {} + while True: + try: + keyword = input(' > ') + if len(keyword.replace(' ', '')) == 0: + pass + elif is_integer(keyword): + self.keywords_integer.append(keyword) + elif is_birthday(keyword): + self.keywords_birthday.append(keyword) + else: + self.keywords_words.append(keyword) + except KeyboardInterrupt: + print('\n') + break - answers['firstname'] = self.prompt('Enter {}\'s first name: '.format(target)) - answers['lastname'] = self.prompt('Enter {}\'s last name: '.format(target)) - answers['nickname'] = self.prompt('Enter {}\'s nick name: '.format(target)) + def combine_words(self): + for word in self.keywords_words: - while True: - bday = self.prompt('Enter {}\'s birthday (mm-dd-yyyy): '.format(target)) + self.keywords_words_cases.append(word) - if not len(bday.strip()): - break + if ' ' in word: + word_parts = word.split(' ') + cases_list = [] - if len(bday.split('-')) != 3: - print('Invalid birthday format\n') - continue - - for _ in bday.split('-'): - if not _.isdigit(): - print('Birthday only requires numbers\n') - continue - - mm, dd, yyyy = bday.split('-') - - if int(mm) > 12 or int(dd) > 31 or len(yyyy) != 4: - print('Invalid birthday\n') - continue - - bday = { 'month': int(mm), 'day': int(dd), 'year': int(yyyy) } - break - - answers['birthday'] = bday - return answers - - def cases(self, word): - return [word.lower(), word.title()] - - def fullname(self, fname, lname): - return ['{}{}'.format(a, b) for a in self.cases(fname) for b in self.cases(lname)] - - def format_names(self): - for _ in range(1000): - - iters = 0 - for data in [self.target, self.spouse, self.child, self.pet]: - - for n in ['firstname', 'lastname', 'nickname']: - - fullname_list = [] - name = data[n].strip() - - if not len(name): - continue - - if not iters: - fullname_list = self.fullname(data['firstname'], data['lastname']) - iters += 1 - - for word in self.cases(name) + fullname_list: - - a, b, c = ('{}{}'.format(word, _), - '{}{}'.format(_, word), - '{0}{1}{0}'.format(_, word) - ) - - if not word in self.passwords: - self.passwords.append(word) - - if not a in self.passwords: - self.passwords.append(a) - - if not b in self.passwords: - self.passwords.append(b) - - if not c in self.passwords: - self.passwords.append(c) - - bday = data['birthday'] - - if bday: - d, e, f, g = ( - '{}{}'.format(word, bday['year']), - '{}{}'.format(bday['year'], word), - '{}{}{}{}'.format(word, bday['month'], bday['day'], bday['year']), - '{}{}{}{}'.format(word, bday['day'], bday['month'], bday['year']) - ) - - if not d in self.passwords: - self.passwords.append(d) - - if not e in self.passwords: - self.passwords.append(e) - - if not f in self.passwords: - self.passwords.append(f) - - if not g in self.passwords: - self.passwords.append(g) - - def generator(self): - self.target = self.question('target') - print('\n') + for part in word_parts: + part_cases = cases(part) + cases_list.append(part_cases) - self.spouse = self.question('spouse') - print('\n') + self.chain_cases(cases_list) - self.child = self.question('child') - print('\n') + for word in (self.keywords_words + self.keywords_words_cases): + self.passwords.add(word) - self.pet = self.question('pet') - print('\n') - - self.format_names() + for i in range(2100): + word_number_combinations = [ + '{}{}'.format(word, i), + '{}{}'.format(i, word), + '{0}{1}{0}'.format(i, word) + ] - output_file = '{}.txt'.format(self.target['firstname'].lower() - if self.target['firstname'] else 'pass.txt') - - with open(output_file, 'wt') as f: - for pwd in self.passwords: - f.write('{}\n'.format(pwd)) + for combination in word_number_combinations: + self.passwords.add(combination) - print('Passwords Generated: {}'. format(len(self.passwords))) + for birthday in self.keywords_birthday: + birthday_parts = birthday.split('-') + birthday_month = birthday_parts[0] + birthday_day = birthday_parts[1] + birthday_year = birthday_parts[2] + word_birthday_combinations = [ + '{}{}'.format(word, birthday_year), + '{}{}'.format(birthday_year, word), + '{}{}{}{}'.format(word, birthday_month, birthday_day, birthday_year), + '{}{}{}{}'.format(word, birthday_day, birthday_month, birthday_year) + ] + + for combination in word_birthday_combinations: + self.passwords.add(combination) + + def generator(self): + self.collect_keywords() + self.combine_words() + + password_file_name = 'passwords_' + str(round(time())) + '.txt' + print(' Passwords Generated: {}'.format(len(self.passwords))) + + with open(password_file_name, 'w+') as password_file: + for password in self.passwords: + password_file.write(password + '\n') + + print(' Passwords written to {}'. format(password_file_name)) + + input(' Press any key to exit ...') + + if __name__ == '__main__': - PassGen().generator() \ No newline at end of file + PassGen().generator() From 3970549d94b785a115c09ad48f8e8b2f79eccf1e Mon Sep 17 00:00:00 2001 From: Castorp Date: Sat, 16 Mar 2019 04:02:16 +0000 Subject: [PATCH 2/9] Update passgen.py --- passgen.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/passgen.py b/passgen.py index df1d2e2..6a091aa 100644 --- a/passgen.py +++ b/passgen.py @@ -98,21 +98,22 @@ def combine_words(self): for combination in word_number_combinations: self.passwords.add(combination) - for birthday in self.keywords_birthday: - birthday_parts = birthday.split('-') - birthday_month = birthday_parts[0] - birthday_day = birthday_parts[1] - birthday_year = birthday_parts[2] - - word_birthday_combinations = [ - '{}{}'.format(word, birthday_year), - '{}{}'.format(birthday_year, word), - '{}{}{}{}'.format(word, birthday_month, birthday_day, birthday_year), - '{}{}{}{}'.format(word, birthday_day, birthday_month, birthday_year) - ] - - for combination in word_birthday_combinations: - self.passwords.add(combination) + for birthday in self.keywords_birthday: + birthday_parts = birthday.split('-') + birthday_month = birthday_parts[0] + birthday_day = birthday_parts[1] + birthday_year = birthday_parts[2] + + word_birthday_combinations = [ + '{}{}'.format(word, birthday_year), + '{}{}'.format(birthday_year, word), + '{}{}{}{}'.format(word, birthday_day, birthday_month, birthday_year), + '{}{}{}{}'.format(word, birthday_month, birthday_day, birthday_year), + '{}{}{}{}'.format(word, birthday_year, birthday_month, birthday_day) + ] + + for combination in word_birthday_combinations: + self.passwords.add(combination) def generator(self): self.collect_keywords() @@ -122,13 +123,12 @@ def generator(self): print(' Passwords Generated: {}'.format(len(self.passwords))) with open(password_file_name, 'w+') as password_file: - for password in self.passwords: + for password in sorted(self.passwords): password_file.write(password + '\n') print(' Passwords written to {}'. format(password_file_name)) - input(' Press any key to exit ...') - + if __name__ == '__main__': PassGen().generator() From be04db0745c46ae4001dfe02244cde5c7892ca00 Mon Sep 17 00:00:00 2001 From: Castorp Date: Sat, 16 Mar 2019 04:26:00 +0000 Subject: [PATCH 3/9] Update passgen.py --- passgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/passgen.py b/passgen.py index 6a091aa..cacbe17 100644 --- a/passgen.py +++ b/passgen.py @@ -85,7 +85,7 @@ def combine_words(self): self.chain_cases(cases_list) - for word in (self.keywords_words + self.keywords_words_cases): + for word in self.keywords_words_cases: self.passwords.add(word) for i in range(2100): From 4a788553aaadc5e2eb35b5fff9b04e7029d301e3 Mon Sep 17 00:00:00 2001 From: Castorp Date: Sat, 16 Mar 2019 04:50:03 +0000 Subject: [PATCH 4/9] Update passgen.py --- passgen.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/passgen.py b/passgen.py index cacbe17..3f0a608 100644 --- a/passgen.py +++ b/passgen.py @@ -85,6 +85,9 @@ def combine_words(self): self.chain_cases(cases_list) + for i in self.keywords_integer: + self.passwords.add(i) + for word in self.keywords_words_cases: self.passwords.add(word) @@ -98,6 +101,16 @@ def combine_words(self): for combination in word_number_combinations: self.passwords.add(combination) + for i in self.keywords_integer: + word_custom_number_combinations = [ + '{}{}'.format(word, i), + '{}{}'.format(i, word), + '{0}{1}{0}'.format(i, word) + ] + + for combination in (word_number_combinations + word_custom_number_combinations): + self.passwords.add(combination) + for birthday in self.keywords_birthday: birthday_parts = birthday.split('-') birthday_month = birthday_parts[0] From 27fb0eddc8d6a52356cb8047b3ae0441bb65b4e0 Mon Sep 17 00:00:00 2001 From: Castorp Date: Sat, 16 Mar 2019 13:09:22 +0000 Subject: [PATCH 5/9] added comments and reverse words / integers --- passgen.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/passgen.py b/passgen.py index 3f0a608..f14e385 100644 --- a/passgen.py +++ b/passgen.py @@ -40,6 +40,7 @@ def __init__(self): self.keywords_birthday = [] self.passwords = set() + # generate all possible combinations of a list of case combinations def chain_cases(self, case_list, i=0, input_combination=''): for case in case_list[i]: combination = input_combination + case @@ -55,6 +56,7 @@ def collect_keywords(self): ' Birthdays have to have the following format: mm-dd-yyyy;\n' ' After entering all your keywords, press CTRL + C to generate the password list;\n') + # collect and categorize keywords while True: try: keyword = input(' > ') @@ -71,8 +73,17 @@ def collect_keywords(self): break def combine_words(self): - for word in self.keywords_words: + # add word in reverse + for i in range(len(self.keywords_words)): + self.keywords_words.append(self.keywords_words[i][::-1]) + + # add integers in reverse + for i in range(len(self.keywords_integer)): + self.keywords_integer.append(self.keywords_integer[i][::-1]) + + # generate all possible case combinations for word and it's parts + for word in self.keywords_words: self.keywords_words_cases.append(word) if ' ' in word: @@ -80,17 +91,24 @@ def combine_words(self): cases_list = [] for part in word_parts: + self.keywords_words_cases.append(part) + self.keywords_words_cases.append(part[::-1]) part_cases = cases(part) cases_list.append(part_cases) self.chain_cases(cases_list) + # add each custom integer as possible password for i in self.keywords_integer: self.passwords.add(i) + # generate passwords using all the parts and case combinations for word in self.keywords_words_cases: + + # add each word/part/case-combination as password self.passwords.add(word) + # passwords with integers 0-2100 around it for i in range(2100): word_number_combinations = [ '{}{}'.format(word, i), @@ -101,6 +119,7 @@ def combine_words(self): for combination in word_number_combinations: self.passwords.add(combination) + # passwords with custom integers around it for i in self.keywords_integer: word_custom_number_combinations = [ '{}{}'.format(word, i), @@ -111,6 +130,7 @@ def combine_words(self): for combination in (word_number_combinations + word_custom_number_combinations): self.passwords.add(combination) + # passwords with birthday combinations in them for birthday in self.keywords_birthday: birthday_parts = birthday.split('-') birthday_month = birthday_parts[0] From 6d763377184d1c67934d69cf6ad42c0f675420da Mon Sep 17 00:00:00 2001 From: Castorp Date: Sat, 16 Mar 2019 13:10:33 +0000 Subject: [PATCH 6/9] Update passgen.py --- passgen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/passgen.py b/passgen.py index f14e385..dda2941 100644 --- a/passgen.py +++ b/passgen.py @@ -40,7 +40,7 @@ def __init__(self): self.keywords_birthday = [] self.passwords = set() - # generate all possible combinations of a list of case combinations + # generate all possible combinations using a list of cases def chain_cases(self, case_list, i=0, input_combination=''): for case in case_list[i]: combination = input_combination + case From 17370af9e4271e814067bb6752b70c0177363486 Mon Sep 17 00:00:00 2001 From: Castorp Date: Sat, 16 Mar 2019 13:15:04 +0000 Subject: [PATCH 7/9] Update passgen.py --- passgen.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/passgen.py b/passgen.py index dda2941..27c621a 100644 --- a/passgen.py +++ b/passgen.py @@ -116,9 +116,6 @@ def combine_words(self): '{0}{1}{0}'.format(i, word) ] - for combination in word_number_combinations: - self.passwords.add(combination) - # passwords with custom integers around it for i in self.keywords_integer: word_custom_number_combinations = [ From 02867c4233853385572edd32488d680a568215e6 Mon Sep 17 00:00:00 2001 From: Castorp Date: Sat, 16 Mar 2019 13:21:53 +0000 Subject: [PATCH 8/9] Update passgen.py --- passgen.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/passgen.py b/passgen.py index 27c621a..b73294e 100644 --- a/passgen.py +++ b/passgen.py @@ -109,16 +109,18 @@ def combine_words(self): self.passwords.add(word) # passwords with integers 0-2100 around it + word_number_combinations = [] for i in range(2100): - word_number_combinations = [ + word_number_combinations += [ '{}{}'.format(word, i), '{}{}'.format(i, word), '{0}{1}{0}'.format(i, word) ] # passwords with custom integers around it + word_custom_number_combinations = [] for i in self.keywords_integer: - word_custom_number_combinations = [ + word_custom_number_combinations += [ '{}{}'.format(word, i), '{}{}'.format(i, word), '{0}{1}{0}'.format(i, word) From 792d9cec9775f4037f39881c94fe9148e3121ee3 Mon Sep 17 00:00:00 2001 From: Castorp Date: Sat, 16 Mar 2019 14:05:45 +0000 Subject: [PATCH 9/9] Update passgen.py --- passgen.py | 79 +++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/passgen.py b/passgen.py index b73294e..7bf1950 100644 --- a/passgen.py +++ b/passgen.py @@ -13,7 +13,7 @@ def is_integer(input_string): return True -def is_birthday(input_string): +def is_date(input_string): if len(input_string) != 10: return False @@ -36,8 +36,8 @@ def __init__(self): self.passwords = [] self.keywords_words = [] self.keywords_words_cases = [] - self.keywords_integer = [] - self.keywords_birthday = [] + self.keywords_integers = [] + self.keywords_dates = [] self.passwords = set() # generate all possible combinations using a list of cases @@ -52,43 +52,46 @@ def chain_cases(self, case_list, i=0, input_combination=''): def collect_keywords(self): print('\n' - ' Please enter keywords associated with the target, e.g. names, numbers, birthdays;\n' - ' Birthdays have to have the following format: mm-dd-yyyy;\n' + ' Please enter keywords associated with the target, e.g. names, numbers, dates (like birthdays);\n' + ' Dates have to have the following format: mm-dd-yyyy;\n' ' After entering all your keywords, press CTRL + C to generate the password list;\n') # collect and categorize keywords while True: try: keyword = input(' > ') + if len(keyword.replace(' ', '')) == 0: pass + elif is_integer(keyword): - self.keywords_integer.append(keyword) - elif is_birthday(keyword): - self.keywords_birthday.append(keyword) + self.keywords_integers.append(keyword) + + elif is_date(keyword): + self.keywords_dates.append(keyword) + else: self.keywords_words.append(keyword) + except KeyboardInterrupt: print('\n') break def combine_words(self): - # add word in reverse - for i in range(len(self.keywords_words)): - self.keywords_words.append(self.keywords_words[i][::-1]) - # add integers in reverse - for i in range(len(self.keywords_integer)): - self.keywords_integer.append(self.keywords_integer[i][::-1]) + for i in range(len(self.keywords_integers)): + self.keywords_integers.append(self.keywords_integers[i][::-1]) # generate all possible case combinations for word and it's parts for word in self.keywords_words: - self.keywords_words_cases.append(word) + self.keywords_words_cases.append(word) # add word + self.keywords_words_cases.append(word[::-1]) # add word in reverse + cases_list = [] if ' ' in word: word_parts = word.split(' ') - cases_list = [] + self.keywords_words_cases.append(''.join(word_parts)[::-1]) # add word without spaces in reverse for part in word_parts: self.keywords_words_cases.append(part) @@ -96,10 +99,14 @@ def combine_words(self): part_cases = cases(part) cases_list.append(part_cases) - self.chain_cases(cases_list) + else: + word_cases = cases(word) + cases_list.append(word_cases) + + self.chain_cases(cases_list) # add each custom integer as possible password - for i in self.keywords_integer: + for i in self.keywords_integers: self.passwords.add(i) # generate passwords using all the parts and case combinations @@ -119,32 +126,32 @@ def combine_words(self): # passwords with custom integers around it word_custom_number_combinations = [] - for i in self.keywords_integer: + for i in self.keywords_integers: word_custom_number_combinations += [ '{}{}'.format(word, i), '{}{}'.format(i, word), '{0}{1}{0}'.format(i, word) ] - for combination in (word_number_combinations + word_custom_number_combinations): - self.passwords.add(combination) - - # passwords with birthday combinations in them - for birthday in self.keywords_birthday: - birthday_parts = birthday.split('-') - birthday_month = birthday_parts[0] - birthday_day = birthday_parts[1] - birthday_year = birthday_parts[2] - - word_birthday_combinations = [ - '{}{}'.format(word, birthday_year), - '{}{}'.format(birthday_year, word), - '{}{}{}{}'.format(word, birthday_day, birthday_month, birthday_year), - '{}{}{}{}'.format(word, birthday_month, birthday_day, birthday_year), - '{}{}{}{}'.format(word, birthday_year, birthday_month, birthday_day) + for combination in (word_number_combinations + word_custom_number_combinations): + self.passwords.add(combination) + + # passwords with date combinations in them + for date in self.keywords_dates: + date_parts = date.split('-') + data_month = date_parts[0] + date_day = date_parts[1] + date_year = date_parts[2] + + word_date_combinations = [ + '{}{}'.format(word, date_year), + '{}{}'.format(date_year, word), + '{}{}{}{}'.format(word, date_day, data_month, date_year), + '{}{}{}{}'.format(word, data_month, date_day, date_year), + '{}{}{}{}'.format(word, date_year, data_month, date_day) ] - for combination in word_birthday_combinations: + for combination in word_date_combinations: self.passwords.add(combination) def generator(self):