From 9e4095e8b75f7235ea5dfef48f06cfef116692d3 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 31 Dec 2016 22:10:12 +0200 Subject: Add hex_to_words and words_to_hex --- pgpwordlist/funcs.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'pgpwordlist/funcs.py') diff --git a/pgpwordlist/funcs.py b/pgpwordlist/funcs.py index 2801839..84d3d0d 100644 --- a/pgpwordlist/funcs.py +++ b/pgpwordlist/funcs.py @@ -33,3 +33,17 @@ def get_hex(word): for hex, t in _words.items(): if word.lower() in t: return hex.lower() + + +def hex_to_words(hexstr): + words = [get_word(hex, i) for i, hex in enumerate(_hex_bytes(hexstr))] + return ' '.join(words) + + +def _hex_bytes(hexstr): + for i in range(0, len(hexstr), 2): + yield hexstr[i:i+2] + + +def words_to_hex(wordstr): + return ''.join(get_hex(w) for w in wordstr.split()) -- cgit v1.2.1