12345678910111213141516171819202122 |
- /* The Atbash cipher is an encryption method in which each letter
- * of a word is replaced with its "mirror" letter in the alphabet:
- * A <=> Z; B <=> Y; C <=> X; etc.
- * Create a function that takes a string and applies the Atbash cipher to it.
- * Capitalisation should be retained.
- * Non-alphabetic characters should not be altered.
- */
- std::string atbash(std::string str) {
- std::string normal = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- std::string bashed = "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA";
- for(int j = 0;j<str.size();j++){
- for(int i = 0;i<normal.size();i++){
- // check the string character with normal character
- if(str[j] == normal[i]){
- // a match has been found
- // replace found character with corresponding bashed character
- str[j] = bashed[i];break;
- }
- }
- }
- return str;
- }
|