forked from corcra/leekspeak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.py
25 lines (22 loc) · 817 Bytes
/
translate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/python
# Encode between onion address and language.
import re
def encode(onion_address, forward_mapping):
"""
Translate from base32 into LANGUAGE.
"""
# this is the hack to get 6 words, sorry world
onion_address = re.sub('http:\/\/','', re.sub('.onion(\/)?$', '', onion_address)) + 'on'
triples = [onion_address[i*3:(i+1)*3] for i in xrange(6)]
triples_mapped = [forward_mapping[x] for x in triples]
onion_language = ' '.join(triples_mapped)
return onion_language
def decode(onion_language, backwards_mapping):
"""
Translate from LANGUAGE into base32.
"""
words = onion_language.split(' ')
assert len(words) == 6
words_mapped = [backwards_mapping[x] for x in words]
onion_address = ''.join(words_mapped)[:-2]+'.onion'
return onion_address