1. ## Cryptogram troubles

Hello,
I realize that this probably isn't able to be solved with a simple answer. So if you could just point me in the right direction of what I should be learning up on that would be much appreciated. I really am just clueless as to what topic this falls under to read about..

Well, onto my question!

How do I get my program to interpret data from a string and then alter it to then mean something else?

IE:
h = i
e = f
l = m
o = p

INPUT: hello
OUTPUT: ifmmp

Code:
```int main()
{

string subject;
string message;

getline (cin, subject);

cout<<"\n\t\t\t\t*MESSAGE*\n";
getline (cin, message);

/* How do I interpret 'message' here and replace letters
with a different letter in its place?

IE:  If the user types "hello" and now I want the program
to recognize "h" "e" "l" "l" "o" and replace these with
"i" "f " "m" "m" "p" */

ofstream a_msg(subject.c_str());
/* Put "ifmmp" into .txt */
a_msg<<message;
a_msg.close();
}```

2. what you're doing is a rotation code. search google for ROT13, and you'll find lots of info on how to do this.

3. Two clues:

Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion

Code:
```	string str = "okay";
str[0] -= 32;
cout << str << endl;```

4. Hehe thank you!! This should definitely be fun

5. If you're just adding 1 to each character, this will suffice:
Code:
`for_each(s.begin(),s.end(),[](char& c){c++;});`
Otherwise make a lookup table, denoting which char to be replaced by what:
Code:
```void rep(char& c)//replaces everything with 'a'
{
bool up_flag(c>='A'&&c<='Z');
if(up_flag)c=tolower(c);
static char table[]=
{
'a','a','a','a','a',
'a','a','a','a','a',
'a','a','a','a','a',
'a','a','a','a','a',
'a','a','a','a','a',
'a'
};
c = table[c-'a'];
if(up_flag)c=toupper(c);
}
//call like this:
for_each(s.begin(),s.end(),rep);```

6. Thank you! Unfortunately I have no clue how to use those examples..Hehe, so I am reading up on "Pointers" as we speak(I think that is the right direction?)...I can not figure out how to declare what is being used in the character table.

I appreciate your reply very much but I think it is a bit past what I have learned so far

I would not be opposed to the first way, but would later like to migrate to the table.

Do I use this like so:
Code:
`for_each(s.begin(),s.end(),[](char& c){c++;});`
Code:
`for_each(s.begin(),s.end(),[](char& d){d++;});`
Code:
`for_each(s.begin(),s.end(),[](char& e){e++;});`
etc. so on and so forth?

sorry

7. Oh...no.
Code:
`    for_each(s.begin(),s.end(),[](char& c){c++;});`
Suppose you have a string variable s.
The above code replaces character element in s with the next character. EG: "ayc" gets turned into "bzd" .
Think of it like a shorthand for this:
Code:
```for(int i=0;i<s.length();i++)
{
s[i]=s[i]+1;
}```
The table on the other hand, replaces characters with those on the table, according to alphabet position. So, the element in the second position replaces 'b' and the last one replaces 'z'.
To use them you need to #include <algorithm> and use a compiler with good C++11 support.

8. YES! THANK YOU

Just had to replace the 's' with "message" and up and running with the table!

I feel silly now

9. Originally Posted by manasij7479
To use them you need to #include <algorithm> and use a compiler with good C++11 support.
Well, if you have a compiler with really good C++11 support, then you might as well write:
Code:
```for (char& c : message)
{
++c;
}```
If you want to use a generic algorithm instead of an explicit loop, then I think std::transform would be better: it would be slightly more verbose, but it is more descriptive than std::for_each.