Write a function method procedure to modify the array to rep
Write a function (method, procedure to modify the array to represent the encoded form of the messagw using a Caesar cipher. Have the main function ask for the shift amount. Pass this information, along with the message array and the number of array element actually used to the enoding function. To get from one character to the character s units along in the alphabet, you can simply add s to the original character. This works for everything except the end of alphabet; here you have to be a bit more clever to cycle back to the begining of the alphabet once the shift is applied. Have the main function invoke the encoding fuction and then invoke \"WriteMessage\" to write out the encoded form of the message.
Solution
/* function to encrypt the string by shifting s positions””
string encode(string text_data, int s)
{
string finalresult = \"\";
// “now we will traverse text
for (int i=0;i<text_data.length();i++)
{
// now we will be encrypting Uppercase letters
if (isupper(text_data[i]))
finalresult += char(int(textdata[i]+s-65)%26 +65);
// now we will be encrypting the lowercase letters
else
finalresult += char(int(text_data[i]+s-97)%26 +97);
}
// now we will be return the resulting string
return finalresult;
}
//This is the driver program to test the above function
int main()
{
string text_data=\"SINGLOUD\";
int s = 8;
cout << \"The Text data is : \" << text_data;
cout << \"\ let us Shift by number of positions: \" << s;
cout << \"\ The Cipher is here : \" << encode(text_data, s);
return 0;
}
