summaryrefslogtreecommitdiff
path: root/pgpwordlist
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2016-12-31 23:44:00 +0200
committerLars Wirzenius <liw@liw.fi>2016-12-31 23:44:00 +0200
commitf20dc3a6271f6b584d4fc6e16c30da4624cfb027 (patch)
tree7dedc85a92844cb654de37f963ebbf1810b74a6b /pgpwordlist
parentbdb0f645bc1bd040cf87be6247fb9f89e9b52f17 (diff)
downloadpy_pgpwordlist-f20dc3a6271f6b584d4fc6e16c30da4624cfb027.tar.gz
Use reverse lookup table for word to hex lookup
Diffstat (limited to 'pgpwordlist')
-rw-r--r--pgpwordlist/funcs.py15
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):