Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- from itertools import permutations
- from string import printable
- def gen_trees():
- ts = []
- for l in permutations(['0','1','2','3']):
- ts += [
- (((l[0], l[1]), l[2]),l[3]),
- ((l[2], (l[0], l[1])),l[3]),
- (l[3],((l[0], l[1]), l[2])),
- (l[3],(l[2], (l[0], l[1])))
- ]
- return ts
- def decode_huff(s, tree):
- clear = ''
- node = tree
- for c in s:
- node = node[int(c)]
- if type(node) is str:
- clear += node
- node = tree
- return clear
- def decode_little(n):
- clear = ''
- while n > 0:
- c = chr(n & 0xff)
- if c not in printable:
- return None
- clear += c
- n >>= 8
- return clear
- text = '''
- 10101011101000110100011101111111011111110111010010110010011100101111001011001001
- 10111001101000111011111110100101111010011101111011001011001001110101011110110011
- 11101011111011110111101111011101111111001011001001011001001110110011100101100100
- 11010001110110011110110100101100100110111001110010111
- '''.replace('\n', '')
- for t in gen_trees():
- s = decode_little(int(decode_huff(text, t), 4))
- if s is not None:
- print s
Advertisement
Add Comment
Please, Sign In to add comment