Hill cipher is polygraphics substitute cipher based on linear agenda.Each number represent by numbers as A=0,B=1,,,,,,Z=25.Then make below operations:
Each plain text represented by the 1*N matrix and key is N*N matrix and matrix multipication apply.The decryption,inverse the matrix.
For example ACT is plain text,convert into cipher text.A=0,C=3,T=19.
The matrix is(0 3 19) in column
We need also select one key to encrypt it..The key is 3*3 matrix forms.Then convert it encrypted text.
The program is given belows:
Each plain text represented by the 1*N matrix and key is N*N matrix and matrix multipication apply.The decryption,inverse the matrix.
For example ACT is plain text,convert into cipher text.A=0,C=3,T=19.
The matrix is(0 3 19) in column
We need also select one key to encrypt it..The key is 3*3 matrix forms.Then convert it encrypted text.
The program is given belows:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void enc(char p[]);
void dec(char c[]);
int k;
void main()
{
char p[20];
clrscr();
printf("enter the plaintext:");
scanf("%s",&p);
printf("enter the key:");
scanf("%d",&k);
enc(p);
getch();
}
void enc(char p[])
{
int i;
char c[50];
for(i=0;i<strlen(p);i++)
{
c[i]=p[i]+k;
if((c[i]>90 && c[i]<94)||(c[i]>122 && c[i]<126))
c[i]=p[i]+k-26;
}
c[i]=NULL;
printf("encrypted message: %s",c);
dec(c);
}
void dec(char c[])
{
int i;
char p[100];
for(i=0;i<strlen(c);i++)
{
p[i]=c[i]-k;
if((c[i]>64 && c[i]<69)||(c[i]>96 && c[i]<100))
p[i]=c[i]-k+26;
}
p[i]=NULL;
printf("\n decrypted message:%s",p);
}