aboutsummaryrefslogtreecommitdiff
path: root/challenge-097/paulo-custodio/cpp/ch-1.cpp
blob: cddd5df19f2a5d8acf79c4c601e52975962644d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
Challenge 097

TASK #1

*/

#include <iostream>
#include <string>
#include <cctype>

// replace in-place by ciphered text
void caeser(int n, std::string& str) {
    for (auto& c : str) {
        if (isalpha(c))
            c = ((toupper(c)-'A'+26-n)%26)+'A';
    }
}

int main(int argc, char* argv[]) {
    std::string str;
    if (argc > 2) {
        int n = atoi(argv[1]);
        for (int i = 2; i < argc; i++) {
            str += argv[i];
            str += " ";
        }
        str.pop_back();
        caeser(n, str);
        std::cout << str << std::endl;
    }
}