WAP to Implement Hill Cipher Algorithm


#include<stdio.h>
#include<conio.h>

void main()
{
          char plaintext[3],index[26],ch;

          int i,j,k,key[3][3],plain_mat[3][1],sum=0,cipher_mat[3][1],n;

          clrscr();

          printf("Enter plaintext:");

          gets(plaintext);

          printf("Enyter key:");

          for(i=0;i<=2;i++)
          {
                   for(j=0;j<=2;j++)
                   {
                             scanf("%d",&key[i][j]);
                   }
          }

          for(i=0;i<=2;i++)
          {
                   for(j=0;j<=2;j++)
                   {
                             printf("%d ",key[i][j]);
                   }
                   printf("\n");
          }

          for(i=0;i<=2;i++)
          {
                   for(j=0;j<1;j++)
                   {
                             plain_mat[i][j]=(int)plaintext[i];
                   }
          }

          for(i=0;i<=2;i++)
          {
                   for(j=0;j<1;j++)
                   {
                             printf("%d",plain_mat[i][j]);
                   }
                   printf("\n");
          }

          for(i=0,ch='a';i<25,ch<='z';i++,ch++)
          {
                   index[i]=(char)ch;
          }

          for(i=0;i<25;i++)
          {
                   printf("%c",index[i]);
          }

       /*         for(i=0;i<=255;i++)
          {
                   printf("%d %c " ,i,i);

          }*/

          printf("\n");
          for(i=0;i<1;i++)
          {
                   for(j=0;j<=2;j++)
                   {
                             sum=0;
                             for(k=0;k<=2;k++)
                             {
                                      sum=sum+(key[j][k]*plain_mat[k][i]);
                             }
                             cipher_mat[j][i]=sum % 26;
                    }
       }

          printf("\n");
          for(i=0;i<=2;i++)
          {
                   for(j=0;j<1;j++)
                   {
                             printf("%c",index[cipher_mat[i][j]]);
                   }
                   printf("\n");
          }

          getch();
}

Related Posts Plugin for WordPress, Blogger...

Engineering material

GTU IDP/ UDP PROJECT

GTU IDP/ UDP PROJECT

Patel free software download

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP