encode procedure, which encodes a message with a given huffman encoding tree