I sometimes need to generate different pincode dictionaries of various lengths and ranges. I decided to practice a bit by writing a small script in python that would also export the dictionary in the format my software requires. This saves me time since I do not need to manually format the dictionary from some other tool.
This is my first attempt at this. I wll probably move the parameter variables outside the function and pass them depending on what else I want this do. I decided to practice a bit with functions as I would like to expand this tool to quickly generate some of the most common dictionaries that I need. Maybe see what it would take to add a status bar or split the dictionary file into parts based on size.
"""
Used to generate a complex numeric pincode dictionary for bruteforce tools.
The length of the passcode is how many digits long a single pincode should be.
Dictionaries above 6 digits may take several minutes. Larger length passcodes
will expodentially take longer. This tool creates the dictionary in ascending
order. The starting combination is the lowest numeric value the passcode could
be. The last combination is the highest numeric value the passcode could be.
It is exported to a plain text file, one pincode per line, using Unix EOL formatting.
"""
import os
path = os.getcwd() #sets export location to working directory
def pincodeGen(): #create a function for the script
#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
pincodeGen()