Jump to content
Fi8sVrs

Python Dictionary File Maker v0.2

Recommended Posts

  • Active Members
Posted

#!/usr/bin/env python
#Python Dictionary File Maker v0.2
#Written By: Absolution

import os, string, time, hashlib, math,sys
from itertools import product, chain

bench = 0

def UI():
print "Dictionary Maker v0.2"
print "Written By: Absolution"
print '''
1 - Make Dictionary
2 - Benchmark System
3 - Exit
'''
ui = raw_input("What would you like to do? => ")
if ui == '1':
DictInfo()
elif ui == '2':
Benchmark()
elif ui == '3':
exit()

def DictInfo():
print '''
1 - Lowercase Letters
2 - Uppercase Letters
3 - Numbers
4 - Uppercase & Lowercase
5 - Uppercase, Lowercase & Numbers
6 - Uppercase, Lowercase & Punctuation
7 - Uppercase, Lowercase, Numbers & Punctuation
8 - Enter your own charset
'''
charset = raw_input("Which charset to use? => ")
maxfilesize = raw_input("Enter max size of each file (MB) => ")
minlength = raw_input("Enter min length => ")
maxlength = raw_input("Enter max length => ")
maxlength = int(maxlength) + 1
md5 = raw_input("Include MD5 Hash? (Y or N) => ")
MakeDict(charset, maxfilesize, minlength, maxlength, md5)

def MakeDict(charset, maxfilesize, minlength, maxlength, md5):
global bench
#Load charset for dictionary maker to use
if charset == '1':
letters = string.ascii_lowercase
elif charset == '2':
letters = string.ascii_uppercase
elif charset == '3':
letters = string.digits
elif charset == '4':
letters = string.ascii_letters
elif charset == '5':
letters = string.ascii_letters + string.digits
elif charset == '6':
letters = string.ascii_letters + string.punctuation
elif charset == '7':
letters = string.ascii_letters + string.digits + string.punctuation
elif charset == '8':
letters = raw_input("Enter characters to use => ")
else:
print 'No valid char set was chosen.'
DictInfo()

combinations = 0
totalsize = 0

for z in range(int(minlength),int(maxlength)):
combs = math.pow(int(len(letters)), z)
combinations = int(combinations) + int(combs)
size = int(combs) * z
totalsize = int(totalsize) + int(size)

wspace = int(combinations) * 2
totalsize = int(totalsize) + int(wspace)

if md5 == "Y":
md5calc = int(combinations) * 34
totalsize = int(totalsize) + int(md5calc)

if totalsize < 1000:
sizeappend = "bytes"
elif totalsize > 1000 and totalsize < 1000000:
sizeappend = "kB"
totalsize = int(totalsize) / 1000
elif totalsize > 1000000 and totalsize < 1000000000:
sizeappend = "MB"
totalsize = int(totalsize) / 1000000
elif totalsize > 1000000000 and totalsize < 1000000000000:
sizeappend = "GB"
totalsize = int(totalsize) / 1000000000
elif totalsize > 1000000000000:
sizeappend = "TB"
totalsize = int(totalsize) / 1000000000000


#Creates variable for filename
y = 1 #Dictionary iteration
filename = 'dict' #Change name to whatever you want
extension = '.txt' #Change extension to whatever you want
dictfile = (filename + str(y) + str(extension)) #File name variable
print ("Writing dictionary that contains the charset %s, with a min length of %s characters and a max length of %s characters." % (letters, minlength, str(int(maxlength) -1)))
print ("You have selected %i different combinations, the output file size will be about %i %s" % (combinations, totalsize, sizeappend))
if bench > 0:
estimatedtime = int(combinations) / int(bench)
estimatedtime = int(estimatedtime) / 60
print("It is estimated that the dictionary creation will take %i minutes to complete" %(estimatedtime))
startstop = raw_input("Are you sure you wish to continue? (Y or N) => ")
if startstop == "N":
exit()
starttime = time.time()

#Create dictionary words
try:
f = open(dictfile,'w') #Initially opens file
for x in xrange(int(minlength),int(maxlength)):
my_chain = product(letters, repeat=x)
print ("Writing %i letter words..." % (x))
for char_set in my_chain:
word = string.join(char_set) #Join letters together in list
word = string.replace(word, ' ', '') #Strip out whitespace
f.write(word + '\n') #Writes current word to file
if md5 == 'Y':
hash = hashlib.md5(word).hexdigest()
f.write(hash + '\n')

#When each word is written to file, check filesize
filesize = os.path.getsize(dictfile) #Get current filesize
filesize = int(filesize)/1048576 #Convert to MB
if int(filesize) >= int(maxfilesize):
print ('%s has reached %i MB. Closing file and making a new one' % (dictfile, filesize))
print ("Last written word was " + str(word))
f.close() #Close current file
y = int(y) + 1 #Move to next file number
dictfile = (filename + str(y) + str(extension)) #Update filename variable
print ('Opening new dictionary file called ' + dictfile)
f = open(dictfile,'w') #Open new file for writing
except KeyboardInterrupt or StandardError or TypeError as error:
f.close()
print ('Process interrupted...' + str(error))
#When done:
f.close() #Finished so close the file
finishtime = time.time()
totaltime = int(finishtime) - int(starttime)
print ("Finished!\n %i dictionary file(s) were created and your files are located in folder %s" %(y, os.getcwd()))
print ('Time Taken: %s seconds' % (str(totaltime)))
UI()

def Benchmark():
global bench
benchfile = "benchmark.txt"
print("Creating benchmark test file...")
benchstart = time.time()
try:
f = open(benchfile,'w')
for x in xrange(1,5):
chain = product('abcdefghijklmnopqrstuvwxyz', repeat=x)
print ("Writing %i letter words..." % (x))
for char_set in chain:
word = string.join(char_set) #Join letters together in list
word = string.replace(word, ' ', '') #Strip out whitespace
f.write(word + '\n')
f.close()
benchstop = time.time()
benchtime = int(benchstop) - int(benchstart)
bench = 475254 / int(benchtime)
except ZeroDivisionError or IOError or ArithmeticError as error:
print "There was an error, trying again."
Benchmark()
print("Your computer has been benched at %i words per second" %(bench))
print("Removing benchmark test file...")
os.remove(benchfile)
UI()

UI()

mirror

scr

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...