1. ## Simple Shift errors...

Hey everyone... I'm writing a very SImple and very BASIC encryption algorithm.

It consists of 3 parts, dividing up the plaintext, dividing up the key, and then xoring, substituting and permutating (if thats a word ha) these individual pieces.

I havent begun the substitution yet but i think that should be easy, nor have i done the xoring but again that's simple as well.

What i am having trouble with is the permutation function.

It's EXTREMELY simple, it simply shifts the string 3 chars to the left on encryption and 3 chars to the right on decryption.

Here's the functions, for some reason the first few characters are getting messed up and i dont know why:
Code:
```void ePermutation(string &block)
{
char temp = block.at(0);
char temp2;
for(int i=0; i<3; i++)
{
//shift everything one to the left
for(int j=15; j>0; j--)
{
temp2 = block.at(j);
block.at(j) = temp;
temp = temp2;
}
}
}

void dPermutation(string &block)
{
char temp = block.at(15);
char temp2;
for(int i=0; i<3; i++)
{
for(int j=0; j<16; j++)
{
temp2 = block.at(j);
block.at(j) = temp;
temp = temp2;
}
}
}```
Thanks!

2. ePermutation
changes chars block.at(15) .. block.at(1)

dPermutation
changes chars block.at(0) .. block.at(15)

looks suspisios

3. ah thanks, ill try to fix that

4. ok well i fixed it so that in ePermutation the second for loop went like this:
Code:
`for(int j=15; j>=0; j--)`
Still not working

5. Nevermind... fixed it, i wasn't resetting the initial temp char each time the second loop looped in the first loop. I moved a bit of code and now it works fine. Thanks for your help!

6. If you want to rotate a string there's a handy rotate function in the algorithm header:
Code:
```#include <string>
#include <algorithm>
#include <iostream>

...

std::string str("Hello World!");
std::cout << "Before rotate : " << str << std::endl;

std::rotate(str.begin(),str.begin()+3,str.end());
std::cout << "Rotate 3 left : " << str << std::endl;

std::rotate(str.begin(),str.end()-3,str.end());
std::cout << "Rotate 3 right: " << str << std::endl;```
Should output:
Code:
```Before rotate : Hello World!
Rotate 3 left : lo World!Hel
Rotate 3 right: Hello World!```