Working encrypt function