refactore all code for encrypting #2