added encode string algorithm