LZW algorithm implementation