Pages

Rabu, 02 April 2014

C code to encrypt and decrypt a message using Vernam Cipher

 // C program to implement Vernam Cipher to encrypt and decrypt a given message. //

#include<stdio.h>

char arr[26][26];
char message[22],key[22],emessage[22],retMessage[22];
int findRow(char);
int findColumn(char);
int findDecRow(char,int);

int main()
{
 int i=0,j,k,r,c;
 clrscr();
 k=96;

 for(i=0;i<26;i++)
 {
   k++;
   for(j=0;j<26;j++)
   {
    arr[i][j]=k++;
    if(k==123)
    k=97;
   }
 }

 printf("
Enter message
");
 gets(message);
 printf("
Enter the key
");
 gets(key);
 // Encryption

 for(i=0;key[i]!=NULL;i++)
 {
   c=findRow(key[i]);
   r=findColumn(message[i]);
   emessage[i]=arr[r][c];
 }
 emessage[i]=

0 komentar:

Posting Komentar