def predict(self, guess): p = Password(guess) p.analyze_frequencies() if self.clf.decision_function([p.letter_frequencies.values()]) + 400 > 0: return True else: return False
def predict(self, guess): p = Password(guess) p.analyze_frequencies() if self.clf.decision_function([p.letter_frequencies.values() ]) + 400 > 0: return True else: return False
def classify_and_generate(): wordfile = "input_dictionaries/linkedin.txt" outputFile = "output_dictionaries/mutations.txt" if len(sys.argv) != 3: print "Number of arguments dif than 2, default filenames will be used" else: wordfile = sys.argv[1] outputFile = sys.argv[2] # delete the content of the output file if there are any with open(outputFile, 'w'): pass print "Creating classifier" classifier = PasswordClassifier() classifier.train(wordfile) print "Classifier built" count = 10000000 # """ <<==== minimum number of passwords to be generated""" letter_frequencies = dict() with open(outputFile, 'a') as output: with open(wordfile, 'r') as words: print "Calculating letter frequencies" for simpleWord in words: # below should be the logic for the creation of the new dictionary password = Password(simpleWord) password.analyze_frequencies() for c in password.letter_frequencies: if c in letter_frequencies: letter_frequencies[c] += password.letter_frequencies[c] else: letter_frequencies[c] = password.letter_frequencies[c] # password.print_frequencies() # mutations = password.mutate() # mutations = password.append_numbers() # write results to output file # output.write('\n'.join(mutations) + "\n") # for c in letter_frequencies: # output.write(c + "," + str(letter_frequencies[c]) + "\n") print "Generating new passwords" n_created = 0 while n_created <= count: tentative_passwords = PasswordGen.generate_passwords( letter_frequencies, 1000, random.randint(7, 14)) output_buffer = [] for p in tentative_passwords: if classifier.predict(p): output_buffer.append(p) P = Password(p) mutations = P.mutate(change_factor=3) output_buffer.extend(mutations) n_created += len(mutations) + 1 output.write('\n'.join(output_buffer) + "\n") print "Created: " + str(n_created) print "done"
def classify_and_generate(): wordfile = "input_dictionaries/linkedin.txt" outputFile = "output_dictionaries/mutations.txt" if len(sys.argv) != 3: print "Number of arguments dif than 2, default filenames will be used" else: wordfile = sys.argv[1] outputFile = sys.argv[2] # delete the content of the output file if there are any with open(outputFile, 'w'): pass print "Creating classifier" classifier = PasswordClassifier() classifier.train(wordfile) print "Classifier built" count = 10000000 # """ <<==== minimum number of passwords to be generated""" letter_frequencies = dict() with open(outputFile, 'a') as output: with open(wordfile, 'r') as words: print "Calculating letter frequencies" for simpleWord in words: # below should be the logic for the creation of the new dictionary password = Password(simpleWord) password.analyze_frequencies() for c in password.letter_frequencies: if c in letter_frequencies: letter_frequencies[c] += password.letter_frequencies[c] else: letter_frequencies[c] = password.letter_frequencies[c] # password.print_frequencies() # mutations = password.mutate() # mutations = password.append_numbers() # write results to output file # output.write('\n'.join(mutations) + "\n") # for c in letter_frequencies: # output.write(c + "," + str(letter_frequencies[c]) + "\n") print "Generating new passwords" n_created = 0 while n_created <= count: tentative_passwords = PasswordGen.generate_passwords(letter_frequencies, 1000, random.randint(7, 14)) output_buffer = [] for p in tentative_passwords: if classifier.predict(p): output_buffer.append(p) P = Password(p) mutations = P.mutate(change_factor=3) output_buffer.extend(mutations) n_created += len(mutations) + 1 output.write('\n'.join(output_buffer) + "\n") print "Created: " + str(n_created) print "done"
def train(self, TrainingFile): training_data = [] with open(TrainingFile) as inputFile: for word in inputFile: p = Password(word) p.analyze_frequencies() training_data.append(p.letter_frequencies.values()) # print training_data self.clf.fit(training_data)