Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string atbash(std::string str) {
- std::string eString{};
- std::vector<char> letters {'a','b','c','d','e','f','g','h','i','j','k','l','m',
- 'n','o','p','q','r','s','t','u','v','w','x','y','z'};
- std::vector<char> uLetters {'A','B','C','D','E','F','G','H','I','J','K','L','M',
- 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
- for(auto& c : str)
- {
- if(!isalpha(c) || c == ' ')
- {
- eString += c;
- continue;
- }
- if(islower(c))
- {
- auto it = std::find(letters.begin(), letters.end(), c);
- int index = std::distance(letters.begin(), it);
- eString += letters.at(letters.size()-1 - index);
- }
- else if(isupper(c))
- {
- auto it = std::find(uLetters.begin(), uLetters.end(), c);
- int index = std::distance(uLetters.begin(), it);
- eString += uLetters.at(uLetters.size()-1 - index);
- }
- }
- return eString;
- }
Advertisement
Add Comment
Please, Sign In to add comment