You have intercepted the data transmission of the
enemy. It is known that the encryption being used is Caesar Cypher. In this
encryption technique, if the letter to be encrypted is the Nth letter in the alphabet,
replace it with the (N-K)th
where K is some fixed integer called the Key. This addition is done modulo 26.
The spaces in the message are not encrypted.
Input Specification
Output Specification
Your output should be the decrypted message, each in a line by itself.
Example Input
LJMM PCBNB
1
LJMM PCBNB
53
Example Output
KILL OBAMA
KILL OBAMA
#include<iostream>#include<string>
using namespace std;
int main()
{
char A[300];
int key,i=0,j=0;
char d;
while(gets(A))
{
key=0;i=0;j=0;
cin>>key;
//Since the counting is cyclic therefore counting multiples of 26 would give the original alphabet.
key=key%26;
for(i=0;i<strlen(A);i++)
{
if(A[i]!=' ')
{
for(j=0;j<key;j++)
{
//Condition for the encryption to count from Z once A is encountered.
if(A[i]=='A')
{
A[i]='Z';
continue;
}
A[i]=A[i]-1;
}
}
}
cout<<A<<endl;
d=getchar();
}
return 0;
}
thank u for sharing this post Meraki Firewall
ReplyDeleteMeraki Cloud