Guest User

Untitled

a guest
May 10th, 2017
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. #!/usr/bin/env python2
  2.  
  3. from itertools import permutations
  4. from string import printable
  5.  
  6. def gen_trees():
  7.     ts = []
  8.     for l in permutations(['0','1','2','3']):
  9.         ts += [
  10.             (((l[0], l[1]), l[2]),l[3]),
  11.             ((l[2], (l[0], l[1])),l[3]),
  12.             (l[3],((l[0], l[1]), l[2])),
  13.             (l[3],(l[2], (l[0], l[1])))
  14.         ]
  15.     return ts
  16.  
  17.  
  18. def decode_huff(s, tree):
  19.     clear = ''
  20.     node = tree
  21.     for c in s:
  22.         node = node[int(c)]
  23.         if type(node) is str:
  24.             clear += node
  25.             node = tree
  26.     return clear
  27.  
  28. def decode_little(n):
  29.     clear = ''
  30.     while n > 0:
  31.         c = chr(n & 0xff)
  32.         if c not in printable:
  33.             return None
  34.         clear += c
  35.         n >>= 8
  36.     return clear
  37.  
  38. text = '''
  39. 10101011101000110100011101111111011111110111010010110010011100101111001011001001
  40. 10111001101000111011111110100101111010011101111011001011001001110101011110110011
  41. 11101011111011110111101111011101111111001011001001011001001110110011100101100100
  42. 11010001110110011110110100101100100110111001110010111
  43. '''.replace('\n', '')
  44.  
  45. for t in gen_trees():
  46.     s = decode_little(int(decode_huff(text, t), 4))
  47.     if s is not None:
  48.         print s
Advertisement
Add Comment
Please, Sign In to add comment