refactored cipher