Saturday, February 28, 2015


Cryptography Lab 1 (caesar cipher encryption)




#include<stdio.h>
#include<conio.h>
#include<string.h>

int caesar_encryption (int, char);                     //encryption function


int main()
{
char plaintext[999],ciphertext[900];
int key,textlength,i;

printf("enter plain text:\n");
gets(plaintext);

printf("enter value of key\n");                         //input the key
scanf("%d",&key);

textlength=strlen(plaintext);
for (i=0;i<textlength;i++)
{
if(plaintext[i]!=32)
{
ciphertext[i]=caesar_encryption(key, plaintext[i]);
   }
   else{
   ciphertext[i]=plaintext[i];
   }
}
 printf("cipher text: \n");
puts(ciphertext);
return 0;
}

int caesar_encryption (int key, char a)
{

  char b;
b=(((a-97)+key)%26)+97;                                   //core incryprion function
 return b;

}

No comments:

Post a Comment