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;
}

Comments

Popular posts from this blog

Non Restoring Division Algorithm Implementation in C

Hackerrank Modified Kaprekar Numbers Solution

Bit Stuffing Code Implementation in Java