Firstly you want to prioritize the logic before formatting. All you're doing is adding an offset to the int value of the character, which is not how Caesar Cipher works.
If I enter 'zzzzz' , where a 'z' is equal to 122, with offset 10, I should not be seeing a bunch of 132, but rather a "wrap-around" back to the beginning of the alphabet. Since 'z' is the last letter of the alphabet, I should be seeing a bunch of 10's, aka 'j', and so the output should be 'jjjjj'.
http://practicalcryptography.com/ciphers/caesar-cipher/
Convert everything to either lowercase or uppercase and figure out how to incorporate the wrap-around for a working caesar shift algo.
For formatting, for now I'd just comment about consistent spacing everywhere. Things are a bit simpler when copy-pasting code if you change your editor options to "insert spaces instead of tabs" , and set it to "4" , for example. From my experience a lot of C++/C# developers use 4 spaces, but of course can vary.
Edit: on naming --
getMessage
is not quite getting a message. It's currently doing some encryption, printing that out, doing some decryption, and printing
that out. There should be separate methods for this. "getSomething" and "setSomething" are more Java style naming. C++ it's more common to just have "Something" as the getter, returning a read-only reference.
1 2 3 4 5 6 7 8 9 10 11 12
|
const string& Message() { return message; }
void SetMessage(const string& x) { message = x; }
void Encrypt()
{
// ...
}
void Decrypt()
{
//...
}
|
Marking things as read-only lets the user of the class know up front that certain parts will not be changed. Methods should only have one function and not try to do too much.