Refactor cipher