refactore all code for encrypting #3