#include <algorithm>
#include <cctype>
#include <iostream>
#include <iterator>
#include <string>

using namespace std;

int main() {
	string msg;
	int key_value;

	cout << "WRITE YOUR MESSAGE:" << endl;
	getline(cin, msg, '\n');

	cout << "PUT A KEY VALUE:" << endl;
	cin >> key_value;

	cout << "THE CODIFIED MESSAGE IS:" << endl;

	transform(cbegin(msg), cend(msg), ostream_iterator<char>(cout), [&](unsigned char i){
		if(isalpha(i)) {
			const auto a = islower(i) ? 'a' : 'A';
			
            i = (i - a + key_value) % 26 + a;
		}
		return i; });
}