refactor encryption into its own function