diff options
-rw-r--r-- | pgpwordlist/funcs.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/pgpwordlist/funcs.py b/pgpwordlist/funcs.py index 4e11b9f..37a17be 100644 --- a/pgpwordlist/funcs.py +++ b/pgpwordlist/funcs.py @@ -21,6 +21,17 @@ import pgpwordlist _words = pgpwordlist.pgp_word_list +def _make_reverse_lookup(words): + rev = {} + for hexstr, t in words.items(): + rev[t[0]] = hexstr + rev[t[1]] = hexstr + return rev + + +_w2hex = _make_reverse_lookup(_words) + + def get_word(hexstr, offset): hexstr = hexstr.lower() t = _words.get(hexstr) @@ -30,9 +41,7 @@ def get_word(hexstr, offset): def get_hex(word): - for hexstr, t in _words.items(): - if word.lower() in t: - return hexstr.lower() + return _w2hex[word.lower()] def hex_to_words(hexstr): |