def _calWordlistPrior(self, word): ## piece of Zak's code that is not used lstfolder = './wordlists/' lstfiles = [('patent', 'patents.lst'), ('science', 'academic.lst'), ('law', 'idcourts.lst'), ('law', 'nycourts.lst'), ('law', 'uscourts.lst'), ('common', 'gsl.lst'), ('medicine', 'medical_roots.lst')] if not hasattr(self, 'lstProbs'): self.lstProbs: Dict[str, float] = {'patent': 0.75, 'science': 0.25, 'law': 0.25, 'common': 0.01, 'medicine': 0.75} if not hasattr(self, 'wordlistdict'): self.wordlistdict = {} for item in lstfiles: lst = Wordlist.load(lstfolder + item[1]) if item[0] in self.wordlistdict: self.wordlistdict[item[0]] += lst else: self.wordlistdict[item[0]] = lst for label in self.wordlistdict: pattern = Wordlist.compile_lst(self.wordlistdict[label]) self.wordlistdict[label] = pattern prior = 1.0 for label in self.wordlistdict: stems = Filter.unstem(word) for s in stems: matches = Wordlist.patternFind(self.wordlistdict[label], w, False) if matches: prior *= self.lstProbs[label] break return prior
def __init__(self, path_to_pattern, path_to_logins="", path_to_passwords="", path_to_screenshots="", no_screenshots=False, DEBUG=False): self.pattern = Action.Action(path_to_pattern, path_to_screenshots, no_screenshots, DEBUG) #Check if pattern is good with command line if path_to_screenshots != '' and self.pattern.useScreenshot() is False: print "A screenshots folder is specified, but there is not screenshot command in pattern file." sys.exit(1) if path_to_logins != '' and self.pattern.useLogin() is False: print "A logins file is specified, but there is not login command in pattern file." sys.exit(1) elif path_to_logins == '' and self.pattern.useLogin() is True: print "A login command is in pattern file, but there is not logins file specified." sys.exit(1) if path_to_passwords != '' and self.pattern.usePassword() is False: print "A passwords file is specified, but there is not password command in pattern file." sys.exit(1) elif path_to_passwords == '' and self.pattern.usePassword() is True: print "A password command is in pattern file, but there is not passwords file specified." sys.exit(1) if self.pattern.useLogin(): self.logins = Wordlist.Wordlist(path_to_logins) else: self.logins = Wordlist.EmptyWordlist() if self.pattern.usePassword(): self.passwords = Wordlist.Wordlist(path_to_passwords) elif self.pattern.useBruteforce(): self.passwords = Wordlist.BruteforceMultipleSize( self.pattern.getBruteforceCharset(), self.pattern.getBruteforceSizeMin(), self.pattern.getBruteforceSizeMax())
# Student's UT EID: MTM2275 # # Course Name: CS 313E # # Date Created: 10/28/12 # # Date Last Modified: 10/28/12 #import needed modules from Wordlist import * from Permutations import * import time #create wordlist, import words of len 5 or 6 wl = Wordlist() #set a filename filename = "scrambledwordslist.txt" #start timer start = time.time() #import words from filename wl.addWordsFromFile( filename , 5 ) wl.addWordsFromFile( filename , 6 ) #stop timer end = time.time() print ("Using words from %s" %filename)
from Wordlist import * wl = Wordlist() wl = Wordlist() wl.addWordsFromFile( "scrambledwordslist.txt", 4 ) wl.addWordsFromFile( "scrambledwordslist.txt", 5 )
def main(): # The next if fakes command line arguments by setting sys.argv explicitly. line = input("") sys.argv = line.split() if len(sys.argv) == 1: # The user didn't supply any command line args, so we have to set # them manually. # Change this if you need to sys.argv = ["Solver.py", "flat"] while len(sys.argv) < 2: print("Please supply a command line argument: flat or sort.") print("Re-enter command.") line = input("") sys.argv = line.split() if sys.argv[1] == "flat": word_lst = Wordlist() print("Using flat unsorted wordlist.") elif sys.argv[1] == "sort": word_lst = SortedWordlist() print("Using sorted wordlist.") start = time.time() word_lst.addWordsFromFile("UnorderedWordlist.txt") # stop timer end = time.time() # Print the name of the list, the number of words in the list, and # the time it took to generate that word list # print ("Using sorted wordlist") print("The Wordlist contains " + str(len(word_lst)) + " words.") print("Building the Wordlist took %2.3f seconds." % (end - start)) print("") while True: # Ask user to input a word word = input("Enter a scrambled word (or EXIT): ") # If the user types "exit", break the program if word.lower() == "exit": print("Thanks for playing! Goodbye.") break # If the word if less than 5 letters or more than 6 letters, # ask the user to input a 5 or 6 letter word if len(word) < 5 or len(word) > 6: print("You did not enter a 5 or 6 letter word, try again") print("") continue # find the number of total and unique permutations of the users word x, y = howManyPerms(word) print("Found %d permutations; %d unique permutations" % (x, y)) # start timer for comparing the permutations generated, with the # list of words from Wordlist(ADT) start2 = time.time() # Initialize a count for the number of permutations checked, before # a match is found in the Wordlist(ADT) count = 0 comparisonsMade = 0 found = False for perm in allPerms(word): count += 1 # If the permutation generated matches a word from the Wordlist(ADT) # print the word found if perm in word_lst._wordlist: index, comparisons = word_lst.findWord(perm) comparisonsMade += comparisons # stop timer for comparing the permutations with words # from Wordlist(ADT) end2 = time.time() print("Found word: " + perm) found = True break if not found: end2 = time.time() print("Word not found. Try again.") # index, comparisons = word_lst.findWord(perm) # stop timer if no permutations are found # end2 = time.time() # Print the time it took to find a permutation of the word, the number # of permutations chaecked, and number of comparisons made print("Solving this jumble took %2.5f seconds." % (end2 - start2)) print("Checked %d permutations" % (count)) print("Made %d comparisons" % (comparisonsMade)) print("")