#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc,char* argv[])
{
int key,j,i;
char message[200];
printf("Enter the secret key: ");
scanf("%d",&key);
if(key < 0)
{
printf("Invalid Key..");
return 1;
}
key = key % 26;
fflush(stdin);
printf("Enter Secret Message: ");
fflush(stdin);
gets(message);
for(i = 0;i < strlen(message);i++)
{
if( (message[i]>=65 && message[i]<=90) )
{
for(j=1;j<=key;j++)
{
if(message[i]>=65 && message[i]<=90)
{
if(message[i]!=65)
message[i] -= 1;
else
message[i] = 'Z';
}
else
message[i]='Z' - 1;
}
}
else if(message[i]>=97 && message[i]<=122)
{
for(j=1;j<=key;j++)
{
if( (message[i]>=97 && message[i]<=122) )
{
if(message[i] != 97)
message[i] -= 1;
else
message[i] = 'z';
}
else
message[i] = 'z' - 1;
}
}
}
printf("Message is: %s\n",message);
return 0;
}
#include<stdlib.h>
#include<string.h>
int main(int argc,char* argv[])
{
int key,j,i;
char message[200];
printf("Enter the secret key: ");
scanf("%d",&key);
if(key < 0)
{
printf("Invalid Key..");
return 1;
}
key = key % 26;
fflush(stdin);
printf("Enter Secret Message: ");
fflush(stdin);
gets(message);
for(i = 0;i < strlen(message);i++)
{
if( (message[i]>=65 && message[i]<=90) )
{
for(j=1;j<=key;j++)
{
if(message[i]>=65 && message[i]<=90)
{
if(message[i]!=65)
message[i] -= 1;
else
message[i] = 'Z';
}
else
message[i]='Z' - 1;
}
}
else if(message[i]>=97 && message[i]<=122)
{
for(j=1;j<=key;j++)
{
if( (message[i]>=97 && message[i]<=122) )
{
if(message[i] != 97)
message[i] -= 1;
else
message[i] = 'z';
}
else
message[i] = 'z' - 1;
}
}
}
printf("Message is: %s\n",message);
return 0;
}
No comments:
Post a Comment