Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using std::string;
- using std::cout;
- using std::endl;
- const string chars = "abcdefghijklmnopqrstuvwxyz !?.";
- const int n = 3;
- string encode(string input)
- {
- string output;
- int pos;
- for(int c = 0; c < input.length(); c++)
- {
- pos = chars.find( tolower(input[c]) );
- if(pos != string::npos)
- {
- output.append( chars.substr( ((pos + n) % 30), 1) );
- }
- }
- return output;
- }
- string decode(string input)
- {
- string output;
- int pos;
- for(int c = 0; c < input.length(); c++)
- {
- pos = chars.find( tolower(input[c]) );
- if(pos != string::npos)
- {
- output.append( chars.substr( ((pos - n) % 30), 1) );
- }
- }
- return output;
- }
- int main()
- {
- string message = "hello world";
- string encoded;
- cout << "Original -> " << message << endl;
- encoded = encode(message);
- cout << "Encoded -> " << encoded << endl;
- cout << "Decoded -> " << decode(encoded) << endl;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement