Question: Write helpful comments for the following code: use Vigenere cipher tech to encrypt and decrypt message The code: #include #include char arr[26][26]; char message[22], key[22],
Write helpful comments for the following code: use Vigenere cipher tech to encrypt and decrypt message
The code:
#include
#include
char arr[26][26];
char message[22], key[22], emessage[22], retMessage[22];
int findRow(char);
int findColumn(char);
int findDecRow(char, int);
int main()
{
int i = 0, j, k, r, c;
k = 96;
for (i = 0; i
{
k++;
for (j = 0; j
{
arr[i][j] = k++;
if (k == 123)
k = 97;
}
}
printf(" Enter message ");
fgets(message, 22, stdin);
printf(" Enter the key ");
fgets(key, 22, stdin);
for (i = 0; key[i] != '\0'; i++) //Use '\0', not NULL
{
c = findRow(key[i]);
r = findColumn(message[i]);
emessage[i] = arr[r][c];
}
emessage[i] = '\0';
printf(" Encrypted message is: ");
for (i = 0; emessage[i] != '\0'; i++) //Use '\0', not NULL
printf("%c", emessage[i]);
//decryption
for (i = 0; key[i] != '\0'; i++) //Use '\0', not NULL
{
c = findColumn(key[i]);
r = findDecRow(emessage[i], c);
retMessage[i] = arr[r][0];
}
printf(" Message Retrieved is: ");
for (i = 0; emessage[i] != '\0'; i++) //Use '\0', not NULL
printf("%c", emessage[i]);
//decryption
for (i = 0; key[i] != '\0'; i++) //Use '\0', not NULL
{
c = findColumn(key[i]);
r = findDecRow(emessage[i], c);
retMessage[i] = arr[r][0];
}
retMessage[i] = '\0';
printf(" Message Retrieved is: ");
for (i = 0; retMessage[i+1] != '\0'; i++)
printf("%c", retMessage[i]);
getchar();
return(0);
}
int findRow(char c)
{
int i;
for (i = 0; i
{
if (arr[0][i] == c)
return (i);
}
}
int findColumn(char c)
{
int i;
for (i = 0; i
{
if (arr[i][0] == c)
return (i);
}
}
int findDecRow(char c, int j)
{
int i;
for (i = 0; i
{
if (arr[i][j] == c)
return (i);
}
}
output should be:

Enter message wikitechy Enter the key technical Encrypted message is: prmmpgrmehj Message Retrieved is wikitechy
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
