Implement Hill Cipher Encryption-Decryption

Aim: Implement Hill Cipher Encryption-Decryption.


Prolog Program Code:


#include<stdio.h> 
#include<conio.h>
void main()
{
    int i, j, ans[25], sum=0, mtrx[2][2],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 The Matrix==>\n");
    for(i = 0; i < 2; i++)
    {
        for(j = 0; j < 2; j++)
        {
            scanf("%d", &mtrx[i][j]);
        }
    }
    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("Encrypted Text Is==>");
    for(i = 0; i < end; i++)
    {
        printf(" %c",((ans[i]) % 26) + 97);
    }
    getch();
        

Output:


Post a Comment

0 Comments