Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Tue Jan 28 22:25:17 2020
- @author: david
- """
- import os
- debug = False
- #File setup
- root_dir = os.path.dirname(os.path.realpath(__file__))
- f = open(root_dir+"\\passwords.txt","w+")
- def get_number_between(low,high):
- """
- Takes two numbers.
- Asks the user to enter a number between those numbers (inclusive).
- Refuses any invalid entries.
- Returns the correctly entered number.
- """
- number = -999
- while (number < low) or (number > high):
- try:
- print("Enter a number between " + str(low) + " and " + str(high)
- + " inclusive.")
- number = int(input())
- except ValueError:
- number = -999
- return number
- print("Enter minimum password length:")
- min_pass_length = get_number_between(1,20)
- print("Enter maximum password length:")
- max_pass_length = get_number_between(1,30)
- characters = [""]
- a_to_z_low = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",
- "q","r","s","t","u","v","w","x","y","z"]
- a_to_z_high = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
- "Q","R","S","T","U","V","W","X","Y","Z"]
- zero_to_9 = ["0","1","2","3","4","5","6","7","8","9"]
- special_chars = ["!","\"","£","$","%","^","&","*","(",")","-","=","+","_","@",
- "#","[","]","{","}","|","\\"]
- print("Select character set:")
- print("1) all (a-z, A-Z, 0-9, special characters)")
- print("2) Manual selection")
- char_select = get_number_between(1,2)
- if char_select == 1:
- print("All characters selected")
- characters = characters + a_to_z_low + a_to_z_high + zero_to_9 + special_chars + [" "]
- print(characters)
- if char_select == 2:
- print("Manual selection")
- print("Current characters:")
- print(characters)
- print("Select character set to add.")
- print("1) a-z")
- print("2) A-Z")
- print("3) 0-9")
- print("4) Special characters")
- print("5) Spaces")
- print("6) Clear selection")
- print("7) Done")
- selected, selected1, selected2, selected3, selected4, selected5 = False, False, False, False, False, False
- while not selected:
- set_select = get_number_between(1,7)
- if set_select == 1 and not selected1:
- characters = characters + a_to_z_low
- selected1 = True
- if set_select == 2 and not selected2:
- characters = characters + a_to_z_high
- selected2 = True
- if set_select == 3 and not selected3:
- characters = characters + zero_to_9
- selected3 = True
- if set_select == 4 and not selected4:
- characters = characters + special_chars
- selected4 = True
- if set_select == 5 and not selected5:
- characters.append(" ")
- selected5 = True
- if set_select == 6:
- characters = [""]
- selected1, selected2, selected3, selected4, selected5 = False, False, False, False, False
- if set_select == 7:
- if characters != [""]:
- selected = True
- else:
- print("Select at leaset one character set.")
- print("Current character set:")
- print(characters)
- password = []
- #Create a list of password characters matching the max length of password
- for i in range(max_pass_length):
- password.append("")
- #Prepopulate the characters of the min length of the password
- for i in range(min_pass_length):
- if debug:
- print(i)
- password[-(i+1)] = characters[1]
- complete = False
- #DEBUG
- if debug:
- print("DEBUG")
- print(password)
- while (not complete):
- current_character = -1
- for character in characters[1:]:
- password[current_character] = character
- pword=""
- for ch in password:
- pword += ch
- pword += "\n"
- if debug:
- print(pword)
- else:
- f.write(pword)
- char_num = 1
- #Test if complete
- if len(set(password)) == 1:
- if password[0] == characters[-1]:
- complete = True
- #If not, increment higher characters accordingly
- else:
- while True:
- if characters.index(password[current_character-char_num]) == len(characters)-1:
- char_num += 1
- else:
- password[current_character-char_num] = characters[characters.index(password[current_character-char_num])+1]
- if char_num > 1:
- password[current_character-char_num+1] = characters[0]
- break
- f.close
- print("\n===Done===")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement