// Program: caesar_decrypt.cpp // decrypts a text by applying a cyclic shift of 3 #include #include #include // for std::noskipws // PRE: s < 95 && s > -95 // POST: if c is one of the 95 printable ASCII characters, c is // cyclically shifted s printable characters to the right void shift (char& c, int s) { assert (s < 95 && s > -95); if (c >= 32 && c <= 126) { // printable if (c + s > 126) c += (s - 95); else if (c + s < 32) c += (s + 95); else c += s; } } int main () { std::cin >> std::noskipws; // don't skip whitespaces! // decryption loop char next; while (std::cin >> next) { shift (next, 3); std::cout << next; } return 0; }