fork download
  1. #include <algorithm>
  2. #include <cctype>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. string msg;
  11. int key_value;
  12.  
  13. cout << "WRITE YOUR MESSAGE:" << endl;
  14. getline(cin, msg, '\n');
  15.  
  16. cout << "PUT A KEY VALUE:" << endl;
  17. cin >> key_value;
  18.  
  19. cout << "THE CODIFIED MESSAGE IS:" << endl;
  20.  
  21. transform(cbegin(msg), cend(msg), ostream_iterator<char>(cout), [&](unsigned char i){
  22. if(isalpha(i)) {
  23. const auto a = islower(i) ? 'a' : 'A';
  24.  
  25. i = (i - a + key_value) % 26 + a;
  26. }
  27. return i; });
  28. }
Success #stdin #stdout 0s 3460KB
stdin
HELLO WORLD
3
stdout
WRITE YOUR MESSAGE:
PUT A KEY VALUE:
THE CODIFIED MESSAGE IS:
KHOOR ZRUOG