Simple(?) substitution cipher help
I am trying to make a simple substitution cipher. Here is what I want the program to do, and how I would do this by hand (the code is where I'm not getting it).
1. Get input from the user. (1 word.)
2. Determine string length;
3. Get the first letter of the string, modify it based on a numeric value, replace it (IE, A+2 = C, B+2 = D, so on).
4. Repeat until end of string.
5. Print output.
I am teaching myself how to program, sort of. So my knowledge of C++ is elementary.
So far, I have the input, string length, loops, and output handled, those are easy. I need help in manipulating the string and letters.
Can someone give a simple example of how to get the first letter of the string, then how to move to the next? And, also, how to change that letter based on a rule, ie, move two positions, etc, then replace it?
All I have for code so far is this:
Code:
#include <iostream>
#include <string>
using namespace::std;
int main()
{
string plaintext;
cout<<"Enter your word here: \n";
cin>> plaintext;
int slength = plaintext.size(); //getting the size of the string;
cout<<"That word is " << plaintext.size() <<" characters. \n";
int loops = slength;
while (loops < slength)
/*this will be the "repeat until done" loop, running until all letters are replaced.*/
{
loops --;
}
system("PAUSE");
return 0;
}
The "system("PAUSE") is only there to hold the window open.
I also realize that I could eliminate a few variables, I will be doing that later.
Any help would be most appreciated!