How to encode and decode string in python?