Encoding and decoding a string