Tech Tip: Move your programming tools such as emulators and IDE`s online into the cloud with high-performance Citrix vdi from CloudDesktopOnline and experience the freedom to remotely catch up with your programming work on your preferred device(PC/Mac/Android/iOS). If you prefer a server, Try dedicated GPU server hosting from Apps4Rent with 24*7*365 days live tech-support & migration assistance.
Today we will learn Hill Cipher algorithm program in c with the output. Hill Cipher algorithm was invented in 1929 by Lester S. Hill. Hill cipher was the first polygraphic cipher. In Hill cipher, each letter is represented by a number modulo 26. To encrypt a message, each n block of letters will be multiplied by the n*n matrix, against modulus 26. The matrix is called a cipher key.
Below is the Hill Cipher program example to know how to compute cipher text from plain text.
/*Hill Cipher Algorithm Program in C */Below is the Hill Cipher program example to know how to compute cipher text from plain text.
Hill Cipher Example |
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,ans[25][1],sum=0,mtrx[25][25],end;
char txt[25];
clrscr();
printf("\nEnter the string : ");
scanf("%s",txt);
for(i=0;i<25;i++)
{
if(txt[i]>=97 && txt[i]<122) {
}
else
{
end=i;
break;
}
}
for(i=0;i<end;i++)
{
txt[i]=txt[i]-'a';
}
printf("\nEnter %dX%d key matrix row by row.\n",end,end);
for(i=0;i<end;i++)
{
for(j=0;j<end;j++)
{
printf("key[%d][%d] : ",i,j);
scanf("%d",&mtrx[i][j]);
}
}
printf("\n");
printf("Key matrix is :\n");
for(i = 0; i <end; i++) {
for(j = 0; j <end; j++)
printf("%d\t", mtrx[i][j]);
printf("\n");
}
for(i=0;i<end;i++)
{
sum=0;
for(j=0;j<end;j++)
{
sum+=mtrx[i][j]*(int)txt[j];
}
ans[i][0]=sum;
}
printf("\nCipher Text is: ");
for(i=0;i<end;i++)
{
printf(" %c",((ans[i][0])%26)+97);
}
getch();
}
#include<conio.h>
void main()
{
int i,j,ans[25][1],sum=0,mtrx[25][25],end;
char txt[25];
clrscr();
printf("\nEnter the string : ");
scanf("%s",txt);
for(i=0;i<25;i++)
{
if(txt[i]>=97 && txt[i]<122) {
}
else
{
end=i;
break;
}
}
for(i=0;i<end;i++)
{
txt[i]=txt[i]-'a';
}
printf("\nEnter %dX%d key matrix row by row.\n",end,end);
for(i=0;i<end;i++)
{
for(j=0;j<end;j++)
{
printf("key[%d][%d] : ",i,j);
scanf("%d",&mtrx[i][j]);
}
}
printf("\n");
printf("Key matrix is :\n");
for(i = 0; i <end; i++) {
for(j = 0; j <end; j++)
printf("%d\t", mtrx[i][j]);
printf("\n");
}
for(i=0;i<end;i++)
{
sum=0;
for(j=0;j<end;j++)
{
sum+=mtrx[i][j]*(int)txt[j];
}
ans[i][0]=sum;
}
printf("\nCipher Text is: ");
for(i=0;i<end;i++)
{
printf(" %c",((ans[i][0])%26)+97);
}
getch();
}
Output:
7 Comments
out put please!!!!
ReplyDeleteunaku output la ila dA.......
DeleteHi Sasi Dhar, Please find updated Hill cipher program with Output.
Deleteolunga output solluda sotta thalaya..sollalana kandapadikku paesuvan da
ReplyDeleteout put please
DeleteHi Male Sundar, Please find updated Hill cipher program with Output.
Deleteoutput please
ReplyDelete