c++ pls follow instructions Hill Cipher The Hill cipher is a type of block ciphe
ID: 3719634 • Letter: C
Question
c++
pls follow instructions
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;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.