def is_guessable(pattern, segments): answer = True if pattern in base_structures: tags = guesser.unpack(pattern) for i, segment in enumerate(segments): if segment.word not in tag_dicts[tags[i]]: answer = False break else: answer = False return answer
def main(base_structures, tag_dicts, file): db = parser.connectToDb() dictionary = parser.getDictionary(db, parser.dict_sets) pos_tagger = BackoffTagger() guessable_count = 0 i = 0 for l in file: password = l.rstrip() if not password : continue segmentations = segment(password, dictionary, db) guessable = False for s in segmentations: tags = pos_tagger.tag([ f.word for f in s if f.dictset_id <= 90]) for j in range(len(s)): if s[j].dictset_id > 90: s[j].pos = None else: s[j].pos = tags.pop(0)[1] pattern = grammar.pattern(s) guessable = is_guessable(pattern, s) if guessable: guessable_count += 1 break print "{}\t{}\t{}".format(password, pattern, guessable, probability(pattern, guesser.unpack(pattern), s)) # print "{}\t{}".format(password, guessable) i += 1 # if i >= 1000: break # print # of guessable passwords print "{} guessable passwords out of {}, ({:%})".format(guessable_count, i, float(guessable_count)/i)