pushed the encryption part in its own function