Simulate Huffman encoding/decoding