#include #include #include #include using namespace std; int main(int argc, char** argv) { int convert, i; string word; char source; vector chars; int offset = 0; int index = 0; char space = ' '; const int lettercount = 26; string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; chars.resize(0); if (argc > 3) { cerr << "Invalid arguments.\n"; return 1; } if (strcmp("-k", argv[1]) == 0) word = argv[2]; else { cout << argv[1] << endl; cerr << "Wrong format for offset.\n"; return 1; } for (i = 0; i < word.size(); ++i) word[i] = toupper(word[i]); cin.get(source); while(!cin.eof()) { source = toupper(source); offset = int(word[index]) - 65; int val = int (source); if ((val > 64) || (val < 91)) { convert = source - 65; //chars.push_back( alphabet[ ( convert + offset ) ] ); cout << alphabet[ ( convert + offset ) ]; } //else //chars.push_back( space ); if ( index < (word.size() - 1 ) ) ++index; else index = 0; cin.get(source); } for (i = 0; i < chars.size(); ++i) cout << chars[i]; return 0; }