diff --git a/src/vigenere/break_vig.py b/src/vigenere/break_vig.py index 5e532b7..d380b9a 100644 --- a/src/vigenere/break_vig.py +++ b/src/vigenere/break_vig.py @@ -4,7 +4,7 @@ import vig import os -def probe(key, substrings): +def probe(key, substrings, words): key_hits = {} for x in range(ord('a'), ord('z')+1): count = 0 @@ -17,16 +17,15 @@ def probe(key, substrings): return {key: val for key, val in key_hits.items() if val == best_val} -def crack(substrings): +def crack(substrings, words): tree = {"": 0} while tree: curr = [key for key, val in sorted( tree.items(), key=lambda ele: ele[1])][-1] - print(curr) if len(curr) == len(substrings[0]): return curr del tree[curr] - tree.update(probe(curr, substrings)) + tree.update(probe(curr, substrings, words)) parser = argparse.ArgumentParser() @@ -36,6 +35,6 @@ args = parser.parse_args() t = ''.join([x for x in open(args.FILE, "r").read().lower() if x.isalpha()]) substrings = [(t[i:i+args.keylen]) for i in range(0, len(t), args.keylen)] - words = open(os.path.dirname(__file__)+"/words.txt", "r").read() -print(crack(substrings)) + +print(crack(substrings, words))