#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
int key,j,i;
char message[200];
printf("Enter the Secret Key: ");
scanf("%d",&key);
if (key < 0)
{
printf("Worng key entered\n");
return 1;
}
key = key % 26;
printf("Enter Message here: ");
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]!=90)
message[i]+=1;
else
message[i]='A';
}
else
message[i]='A'+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]!=122)
message[i]+=1;
else
message[i]='a';
}
else
message[i]='a'+1;
}
}
}
printf("Encrypted Message: %s\n",message);
return 0;
}
#include<stdlib.h>
#include<string.h>
int main(void)
{
int key,j,i;
char message[200];
printf("Enter the Secret Key: ");
scanf("%d",&key);
if (key < 0)
{
printf("Worng key entered\n");
return 1;
}
key = key % 26;
printf("Enter Message here: ");
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]!=90)
message[i]+=1;
else
message[i]='A';
}
else
message[i]='A'+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]!=122)
message[i]+=1;
else
message[i]='a';
}
else
message[i]='a'+1;
}
}
}
printf("Encrypted Message: %s\n",message);
return 0;
}
No comments:
Post a Comment