Refactors duplicate code into method 'run_cipher'