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

Write helpful comments for the following code: use Vigenere cipher tech to encry

ID: 3861489 • Letter: W

Question

Write helpful comments for the following code: use Vigenere cipher tech to encrypt and decrypt message

The code:

#include<stdio.h>

#include <stdlib.h>

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<26; i++)

{

k++;

for (j = 0; j<26; 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] != ''; i++) //Use '', not NULL

{

c = findRow(key[i]);

r = findColumn(message[i]);

emessage[i] = arr[r][c];

}

emessage[i] = '';

printf(" Encrypted message is: ");

for (i = 0; emessage[i] != ''; i++) //Use '', not NULL

printf("%c", emessage[i]);

//decryption

for (i = 0; key[i] != ''; i++) //Use '', 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] != ''; i++) //Use '', not NULL

printf("%c", emessage[i]);

//decryption

for (i = 0; key[i] != ''; i++) //Use '', not NULL

{

c = findColumn(key[i]);

r = findDecRow(emessage[i], c);

retMessage[i] = arr[r][0];

}

retMessage[i] = '';

printf(" Message Retrieved is: ");

for (i = 0; retMessage[i+1] != ''; i++)

printf("%c", retMessage[i]);

getchar();

return(0);

}

int findRow(char c)

{

int i;

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

{

if (arr[0][i] == c)

return (i);

}

}

int findColumn(char c)

{

int i;

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

{

if (arr[i][0] == c)

return (i);

}

}

int findDecRow(char c, int j)

{

int i;

for (i = 0; i<26; 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

Explanation / Answer

#include<stdio.h> //include header file
#include <stdlib.h>//include standard library file
char arr[26][26]; // Assigning alphabets in char array
char message[22], key[22], emessage[22], retMessage[22];
int findRow(char);// declaring variables
int findColumn(char);
int findDecRow(char, int);
int main()
{
int i = 0, j, k, r, c;
k = 96;
for (i = 0; i<26; i++)//Started for loop
{
k++;
for (j = 0; j<26; j++)
{
arr[i][j] = k++;
if (k == 123)
k = 97;
}
}
printf(" Enter message "); //Getting Input message to encrypt
fgets(message, 22, stdin); //used to get the message
printf(" Enter the key ");//Getting Key values to encrypt the message
fgets(key, 22, stdin);
for (i = 0; key[i] != ''; i++) //Use '', not NULL
{
c = findRow(key[i]);
r = findColumn(message[i]);
emessage[i] = arr[r][c];
}
emessage[i] = '';
printf(" Encrypted message is: ");
for (i = 0; emessage[i] != ''; i++) //Use '', not NULL
printf("%c", emessage[i]); //Displaying the encrypted message
//decryption
for (i = 0; key[i] != ''; i++) //Use '', 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] != ''; i++) //Use '', not NULL
printf("%c", emessage[i]);// Displaying the retrived message
//decryption
for (i = 0; key[i] != ''; i++) //Use '', not NULL
{
c = findColumn(key[i]);
r = findDecRow(emessage[i], c);
retMessage[i] = arr[r][0];
}
//Here again we are decrypting the encrypted message
retMessage[i] = '';
printf(" Message Retrieved is: ");
for (i = 0; retMessage[i+1] != ''; i++)
printf("%c", retMessage[i]);// Printed the message retrived
getchar();
return(0);
}
int findRow(char c)
{
int i;
for (i = 0; i<26; i++)
{
if (arr[0][i] == c)
return (i);
}
}
//Finding which coumn to decrypt
int findColumn(char c)
{
int i;
for (i = 0; i<26; i++)
{
if (arr[i][0] == c)
return (i);
}
}
//Finding decrypted row
int findDecRow(char c, int j)
{
int i;
for (i = 0; i<26; i++)
{
if (arr[i][j] == c)
return (i);
}
}

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