I updated my pincode generator to now easily export the full 4 and 6 digit dictionary files. I added two more functions for this and it no longer closes after it runs. It will now allow you to create multiple dictionary files without having to rerun the script. It also checks for invalid input from the user.
I was experementing with some different progress bar options, however each them greatly slowed the process so I decided to leave them out. I might add them back for troubleshooting to help see if the generator ever gets stuck.
Next I plan on learning how to split the output into specified file sizes. The tool I use, sometimes has difficulty reading large dictionaries. It would be very helpful if I could specify the max file size during the generation. Maybe that should be the next thing I learn.
#Import required modules
import os
import time
def fourDigit(): #fucntion to create a text file of all possible 4 digit combinations in ascending order
print()
filename = str('All_4_Digit.txt')
f = open(filename, "w", newline="\n", encoding="UTF-8") #creates the dictionary file with proper formatting
for num in range(0, 9999): #sets the starting combination 0000 and ending 9999
f.write(str(num).zfill(4) + "\n") #writes all 4 digit combinations to the file
f.write(str(9999)) #writes last combination from range
f.close()
print()
print('Exported: ' + filename + ' to: ' + path)
def sixDigit(): #fucntion to create a text file of all possible 6 digit combinations in ascending order
print()
filename = str('All_6_Digit.txt')
f = open(filename, "w", newline="\n", encoding="UTF-8") #creats dictionary file with proper formatting
for num in range(0, 999999): #sets the starting combination 000000 and ending 999999
f.write(str(num).zfill(6) + "\n") #writes all possible combinations to the file
f.write(str(999999)) #writes last possible combination
f.close()
print()
print('Exported: ' + filename + ' to: ' + path)
def custom(): #function to create a custom range and length dictionary
#Set pincode length, lowest and highest value combinations
size = int(input('Enter the length of passcode: '))
start = int(input('Enter starting combination: '))
end = int(input('Enter last combination: '))
print()
#show the user something while it is running.
status = ('Generating ' + str(size) + ' digit dictionary ' + str(start).zfill(size) + ' to ' + str(end).zfill(size) + ': ')
filename = str(start).zfill(size) + '_to_' + str(end).zfill(size) + '_Dictionary.txt'
#Create export file with formatting
f = open(filename, "w", newline="\n", encoding="utf-8")
#Loop through all possible combination within the speciifed range
for num in range(start, end):
f.write(str(num).zfill(size) + "\n") #write combination in ascending order
f.write(str(end).zfill(size)) #write last combination
f.close()
print()
print('Exported: ' + filename + ' to: ' + path) #show the user the name and location of the export
c = 0 #sets users choice variable to 0
path = os.getcwd() #gets current working directory to display location of file to the user
while c < 6: #loop to make selection and allows to generate multiple dictionaries without closing
#Display choices to the user
print()
print('1. Generate all 4 digit combinations')
print('2. Generate all 6 digit combinations')
print('3. Generate a custom range dictionary')
print('4. Exit')
print()
try:
c = int(input('Enter 1 - 4: '))
#Select function based on user input
if c == 1:
fourDigit()
c = 0
time.sleep(.5)
elif c == 2:
sixDigit()
c = 0
time.sleep(.5)
elif c == 3:
custom()
c = 0
time.sleep(.5)
elif c == 4:
print('Goodbye')
time.sleep(.5)
raise SystemExit
else:
print('Invalid Entry')
time.sleep(2)
c = 0
#Catch for invalid input
except ValueError:
print('Invalid Entry')
c = 0
time.sleep(2)