Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, struct
- def main():
- f = open(sys.argv[1], "rb")
- symbols = []
- for c in xrange(256):
- n = struct.unpack(">L", "\x00" + f.read(3))[0]
- if n == 0:
- continue
- symbols.append((n, chr(c), None, None))
- symbols = sorted(symbols)
- while len(symbols) > 1:
- a = symbols[0]
- b = symbols[1]
- newsymb = (a[0] + b[0], a[1] + b[1], a, b)
- symbols = symbols[2:]
- symbols.append(newsymb)
- symbols = sorted(symbols)
- of = open(sys.argv[1] + ".disenchanted", "wb")
- root = symbols[0]
- node = root
- while True:
- c = f.read(1)
- if len(c) == 0:
- break
- for i in xrange(8):
- bit = (ord(c) >> (7-i)) & 1
- if bit == 0:
- node = node[2]
- else:
- node = node[3]
- if node[2] is None:
- of.write(node[1])
- node = root
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement