Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ pls follow instructions Hill Cipher The Hill cipher is a type of block ciphe

ID: 3719634 • Letter: C

Question

c++
pls follow instructions

Hill Cipher The Hill cipher is a type of block cipher that uses a n × n matrix as a key: that is, E(P) KP mod m where K is an n × n matrix, P is a n × 1 matrix and m is the size of the plaintext. The key of the Hill cipher, however, must be invertible in order to decrypt the encoded message. Write a program that opens a file and encrypt it using the Hill cipher. The first line of the file will be the encryption key and the remainder of the file is the actual message. Your program must first verify that the key is valid. If it is valid, create an encrypted file of the remainder of the original file, and then, display the decryption key on the screen; otherwise, create a copy of the original file excluding the first line. Note: The plaintext is the alphabet (A through Z). And the key wll be a 2 x 2 matrix listed by row.

Explanation / Answer

#include<stdio.h>

#include<iostream>

using namespace std;

int check(int x)

{

if(x%2==0)

return 0;

int a=x/2;

int b=2*(a+1);

int c=b-x;

return c;

}

int main(int argc, char **argv)

{

int l, i, j;

int temp1;

int k[2][2];

int p[2][1];

int c[2][1];

char ch;

cout<<"This cipher has a key lengh of 4. i.e. a 2*2 matrix. Enter the 4charatcer key.";

for(i=0; i<2; ++i)

{

for(j=0; j<2; ++j)

{

cin>>"%c", &ch;

if(65<=ch&&ch<=91)

k[i][j]=(int) ch %65;

else

k[i][j]=(int) ch % 97;

}

}

for(i=0; i<2;++i)

{

for(j=0;j<2;++j)

{

cout<<k[i][j]<<" ";

}

cout<< endl;

}

cout<<" Enter the length of the string to be encoded.";

cin>>1;

temp1=check(1);

if(temp1>0)

cout<<"You have to enter"<<temp1<<"character"

char pi[1+temp1];

cout<<" Enter the string";

for(i=-1; i<1+temp1;++i)

{

cin>>pi[i];

}

int temp2=1;

int n=(1+temp1)/2;

int temp3;

int flag=0;

int count;

cout<<" The encoded Cipher is:";

while(n>0)

{

count=0;

for(i=flag; i<flag+2; ++i)

{

temp3=(int) pi[i]% 65;

else

temp3=(int) pi[i]%97;

p[count][0]=temp3;

count=count+1;

}

int k1;

for(i=0; i<2;++i)

c[i][0]=0;

for(i=0;i<2;++i)

{

for(j=0;j<1;++j)

{

for(k1=0; k1<2; ++k1)

c[i][j]+=k[i][k1]*p[k1][j];

}

}

for(i=0; i<2; ++i)

{

c[i][0]=c[i][0]%26;

cout<<"%c", (char) (c[i][0]+65));

}

n=n-1;

flag=flag+2;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote