# Playing with passphrases [6 kyu] [Playing with passphrases](https://www.codewars.com/kata/559536379512a64472000053) 6 kyu ## Solution ```cpp= /** *** Author: R-CO *** E-Mail: daniel1820kobe@gmail.com *** Date: 2020-08-05 **/ #include <algorithm> #include <cctype> #include <cstdlib> #include <iostream> using std::cout; using std::endl; #include <vector> struct TestCaseStruct { struct Input { std::string origin; int shift; } input; std::string expected_output; }; class PlayPass { public: static std::string playPass(const std::string &s, int n) { std::string output = s; for (auto &c : output) { if (isalpha(c)) { c = CircularShift(c, n); } else if (isdigit(c)) { c = ComplementTo9(c); } } for (size_t index = 0; index < output.size(); index += 2) { output[index] = toupper(output[index]); } for (size_t index = 1; index < output.size(); index += 2) { output[index] = tolower(output[index]); } std::reverse(output.begin(), output.end()); return output; } private: static char CircularShift(const char c, const int n) { char output = c + n; if (isupper(c)) { if (output > 'Z') { output = output - 'Z' + 'A' - 1; } } else { if (output > 'z') { output = output - 'z' + 'a' - 1; } } return output; } static char ComplementTo9(const char c) { return '9' - c + '0'; } }; int main(int argc, char *argv[]) { /* */ TestCaseStruct test_cases[] = { {{"I LOVE YOU!!!", 1}, "!!!vPz fWpM J"}, {{"I LOVE YOU!!!", 0}, "!!!uOy eVoL I"}, {{"AAABBCCY", 1}, "zDdCcBbB"}, {{"MY GRANMA CAME FROM NY ON THE 23RD OF APRIL 2015", 2}, "4897 NkTrC Hq fT67 GjV Pq aP OqTh gOcE CoPcTi aO"}}; PlayPass solution; for (const auto &test_case : test_cases) { if (solution.playPass(test_case.input.origin, test_case.input.shift) == test_case.expected_output) { cout << "test case \"" << test_case.input.origin.c_str() << "\" is pass." << std::endl; } else { cout << "test case \"" << test_case.input.origin.c_str() << "\" is fail." << std::endl; } } return EXIT_SUCCESS; } ``` ## Result ![](https://i.imgur.com/5pmjRgm.png) ###### tags: `CodeWars` `C++`