Only thing I can really see wrong is that you are trying to manipulate and then assign the entire string to a char type variable on line 16. Try getting a single char from the string at a time using either the [] operator or the at member function. Both are described here:
http://www.cplusplus.com/reference/string/string/
Using that you can get the string size to use as the test against i for the for loops to ensure you iterator over every character in the string (the way you have it set up, it will only do the first 3 characters) replace password with password[i] on line 16. However, you'll also need to re-assign the encrypted char back to the string, so you could do something like simply do that back to password[i]. Better yet, you could do all that on one line and not use a separate char variable at all, something like:
1 2 3 4
|
string encstr; // moved this outside the for loop so it won't go out of scope when the loop ends
for (int i=0; i < password.size; i++)
encstr[i] = (((((int)password[i])+1) - 1 + shift) % 127)+ 1;
|
I haven't tested that code so it may need some fine tuning, but that should help some. You might need to recast the result of the expression back to char before assigning it to encstr[i], not sure on that.
All in all though, the whole algorithm for the encoding could be simplified alot. If you look at it, you are adding 1, then subtracting one, then adding 2 before the modulus. Why not just add 2 after the cast? It reduces the code and the amount of work considerably with exactly the same effect.
encstr[i] = (((int)password[i] + 2) % 127)+ 1;
Edit: Moved encstr outside the for loop.