# Hill Cipher Algorithm Program in C

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.

Also Read : Hill cipher code in python

Below is the Hill Cipher program example to know how to compute cipher text from plain text. Hill Cipher Example

/*Hill Cipher Algorithm Program in C */

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,ans,sum=0,mtrx,end;
char txt;
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]=sum;
}

printf("\nCipher Text is: ");
for(i=0;i<end;i++)
{
printf(" %c",((ans[i])%26)+97);
}

getch();
}

Output: Hill Cipher Algorithm Program in C - Encryption - Output

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.

1. 1. unaku output la ila dA.......

2. Hi Sasi Dhar, Please find updated Hill cipher program with Output.

2. olunga output solluda sotta thalaya..sollalana kandapadikku paesuvan da

1. 2. 3. 4. 