Encrypt function bug fix