diff options
author | Lars Wirzenius <liw@liw.fi> | 2016-12-31 22:10:12 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2016-12-31 22:10:12 +0200 |
commit | 9e4095e8b75f7235ea5dfef48f06cfef116692d3 (patch) | |
tree | 79be1b0560404712a4ce35935aa519d473cb2df0 /pgpwordlist/funcs.py | |
parent | 23683ca2bc1d9dd07e4ebee6ba348a5e7eaee1bb (diff) | |
download | py_pgpwordlist-9e4095e8b75f7235ea5dfef48f06cfef116692d3.tar.gz |
Add hex_to_words and words_to_hex
Diffstat (limited to 'pgpwordlist/funcs.py')
-rw-r--r-- | pgpwordlist/funcs.py | 14 |
1 files changed, 14 insertions, 0 deletions
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()) |