0% found this document useful (0 votes)
200 views3 pages

Cipher.: Program 3: Write A Program To Implement Hill

This program implements the Hill cipher to encrypt plaintext using a key matrix. It takes in a plaintext string and the key matrix as input. It then divides the plaintext into blocks matching the size of the key matrix. Each block is treated as a vector and multiplied with the key matrix to generate the encrypted vector. The encrypted characters are obtained by taking the encrypted vector values modulo 26 and adding 97. The encrypted text is then printed as output.

Uploaded by

Akshat jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
200 views3 pages

Cipher.: Program 3: Write A Program To Implement Hill

This program implements the Hill cipher to encrypt plaintext using a key matrix. It takes in a plaintext string and the key matrix as input. It then divides the plaintext into blocks matching the size of the key matrix. Each block is treated as a vector and multiplied with the key matrix to generate the encrypted vector. The encrypted characters are obtained by taking the encrypted vector values modulo 26 and adding 97. The encrypted text is then printed as output.

Uploaded by

Akshat jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PROGRAM 3: WRITE A PROGRAM TO IMPLEMENT HILL

CIPHER.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream.h>
void main()
{
int i,j,key[5][5],ikey[5][5],row,col,plen,suc;
int devide,count,h,k,no,p1[100],e1[100],d1[100],m,pp[10],temp;
char p[100],e[100],d[100],clen,det;
clrscr();
printf("Enter your plaintext : ");
gets(p);
plen=strlen(p);
printf("\n HOW MANY SUCCESSIVE ELMENTS YOU WILL TAKE IN PLAINTEXT : ");
scanf("%d",&suc);
row=suc;
col=suc;
printf("\n ENTER ELEMENTS OF KEY MATRIX (row by row) : ");
for(i=0;i<row;i++)
for(j=0;j<col;j++)
scanf("%d",&key[i][j]);
for(i=0;i<row;i++)
{printf("\n");
for(j=0;j<col;j++)
printf(" %d ",key[i][j]);
}
devide=(plen+1)/suc;
count=0;
no=0;
for(h=0;h<devide;h++)

AKSHAT JAIN 1703013008


{

for(i=0;i<suc;i++)
{ if(p[count]!='\0')
{p1[i]=p[count]-97;
count++;
}
}
for(i=0;i<suc;i++)
{ e1[no]=0;
for(k=0;k<suc;k++)
{e1[no]=e1[no]+(key[i][k]*p1[k]);
}
no++;
}
}
printf("\n PLAIN TEXT : ");
puts(p);
printf("\n ENCRYPTED TEXT : ");
for(i=0;i<plen;i++)
{e[i]=(e1[i]%26)+97;
printf("%c",e[i]);
}
getch();
}

AKSHAT JAIN 1703013008


OUTPUTS:

AKSHAT JAIN 1703013008

You might also like