Answer:
The code is given below
{
string cipher = "";
//Where cipher is an algorithm used.
for (int y = 0; iy< msg.length(); i++)
{
if(msg[i]!=' ')
/* applying encryption formula ( c x + d ) mod m
{here x is msg[i] and m is 26} and added 'A' to
bring it in range of ascii alphabet[ 65-90 | A-Z ] */
cipher = cipher +
(char) ((((a * (msg[i]-'A') ) + b) % 26) + 'A');
else
cipher += msg[i];
}
return cipher;
}