LZ78 encoding and decoding