Monday 17 March 2014


Caesar Cipher

Don't bother hand solving  caesar cipher anymore.
Just use this C++ program. It will output you the 25 possible shifts.
Choose what makes sense. Simple!

#include<stdio.h>
#include<string.h>//for strlen()
using namespace std;
int main()
{
int i,j,l;
char c,s[401];
scanf("%[^\n]s",s);//reads strings with spaces too
l=strlen(s);
i=0;
for(j=1;i=0,j<=25;j++,printf(" %s\n",s))
while(s[i])
{
if(s[i]==' ' || s[i]=='\t')//skip whitespaces
{
i++;//skip to next char in case of a whitespace
}
else//shift right by 1 and store result in initial string
{
c=s[i];
if((c>='A' && c<='Z') || (c>='a' && c<='z'))
{
if(c=='Z' || c=='z')
s[i]-=25; //z->a
else
s[i]++; //a->b   , b->c , ... , y->z 
}
i++;
}
}
return 0;
}