title: How do you decode a string in ternary (or any unusual base)?
body: <p>For binary, quaternery, octonery and hex it's clear for me how to convert a stream of them to plain text. Can anybody help me understand how should I do it for ternary, quinary, senary and other bases? (<a href="https://nofile.io/f/6e9PSwZh2cn/ternary.txt" rel="nofollow noreferrer">Here</a>'s a ternary example, a python script would be appreciated) 
  So far I've tried: </p>
  
  <ul>
  <li>Decoding every number to it's binary counterpart, <code>0-&gt;00</code>, <code>1-&gt;01</code> and <code>2-&gt;10</code></li>
  <li>Creating chunks of 3 characters and map them to English alphabets which didn't work either: <code>000-&gt;a</code>,<code>001-&gt;b</code> and so on till <code>221-&gt;z</code> </li>
  </ul>
  
  <p>Here's my code: </p>
  
  <pre><code>from numpy import *
  import binascii
  
  base =3
  base_data = ''
  with open ("./base%s"%base,'r') as b3:
      for line in b3:
          base_data = base_data + line.strip('\r\n')
  output = []
  all_nums_in_base = range(base)
  list_chars = list(base_data)
  final = ''
  for char in list_chars:
      if char == '0':
          output += ['0']
      elif char == '1':
          output += ['1']
      elif char == '2':
          output += ['1','0']
  output = ''.join(output)
  n = int('ob'+output,2)
  print binascii.unhexlify('%x' % n)
  </code></pre>
  
  <p>and my result is in this format: </p>
  
  <pre><code>JMN4,�J�j�T*2VYI�F�%��TjYCL���Y�E�&amp;�
  �I��̚dYCL�Z�
  �K*�թ��-P��Qie�K"q�jL��5j�Y���K0�C�K2i�f�
  </code></pre>