string Cipher::key_rotate(string key)
{
char temp;
char replace;
int count = 0;
for(int i=0;i<key.length();i++)
{
count++;
}
cout << count << endl;
//Does the shifting of the key.
for(int i=0;i<count;i++)
{
temp = key.at( i ); //takes the iTH spot in the key and stores it into a char variable.
replace = key.at(i+1); //
key.append(1, temp);
}
//testing if the new key has been shifted.
for(int i=0;i<key.length();i++)
{
cout << key.at( i );
}
return key;
}
What I want this function to do is take the key, which for the sake of this is
string key = "defghijklmnopqrstuvwxyzabc";
I would like to use the function above that I wrote to take whatever is at the iTH spot of the key and store it in a temp variable. Then take everything in the string and move it up one spot. So it would take the string:
string key = "defghijklmnopqrstuvwxyzabc";
And make it into:
string key = "efghijklmnopqrstuvwxyzabcd";
And keep moving everything from the front to the back. The problem I keep coming across is that it just makes the key string longer and just flubs up the whole thing. I've tried a few things to help it to not infinitely change string and so now I use count so it just runs as long as the key string is. I still get something stupid like:
Hmm, I don't know if there is some standard way to do this, but how I would do it is so
1. Copy string minus element 0 into a temp string
2. Take element 0 and append it to temp string
3. Replace main string with temp string
4. Rinse and repeat