Hackerrank Caeser Cipher Solution

The below program is the solution of Caeser Cipher in implementation domain. You can get the program HERE.

Output : 

Code :

#include<iostream>
using namespace std;

int main()
{
int x,t,m;
cin>>x;
string s;
cin>>s;
cin>>t;
while(t>26)
{
t=t-26;
}
for(int i=0;i<s.length();i++)
{
m=s[i]+t;
if(islower(s[i]))
{
if(m>122)
{
m=m-122;
m+=96;
}

}
else if(isupper(s[i]))
{
if(m>90)
{
m=m-90;
m+=64;
}
}
//cout<<m;
if(isalpha(s[i]))
cout<<(char)m;
else
cout<<s[i];
}
return 0;
}

Catch Me On

Bikash Panda

Blogger / Embedded System Developer at WGLabz
A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.
Bikash Panda
Catch Me On

Latest posts by Bikash Panda (see all)

Related posts