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

This is the code I was able to come up with, so far: /* * File: main.cpp * Autho

ID: 3750615 • Letter: T

Question

This is the code I was able to come up with, so far:


/*
* File: main.cpp
* Author: carlosblanco
*https://code.sololearn.com/cKAqC9car7Xx#java
* https://stackoverflow.com/questions/26941470/initializing-2d-char-array-in-c
* https://www.quora.com/Is-it-a-good-practice-to-declare-the-counter-inside-a-loop-or-outside-My-professor-says-it-is-much-better-practice-to-declare-all-variables-at-the-beginning-of-a-block-is-this-true
* Created on September 16, 2018, 11:51 AM
*/

#include <cstdlib>
#include <stdio.h>
#include <string.h>

using namespace std;

/*
*
*/
int main(int argc, char** argv) {

char square[5][5];

square[0][0] = 'c';
square[0][1] = 'r';
square[0][2] = 'a';
square[0][3] = 'z';
square[0][4] = 'y';
square[1][0] = 'b';
square[1][1] = 'd';
square[1][2] = 'e';
square[1][3] = 'f';
square[1][4] = 'g';
square[2][0] = 'h';
square[2][1] = 'i';
square[2][2] = 'j';
square[2][3] = 'k';
square[2][4] = 'l';
square[3][0] = 'm';
square[3][1] = 'n';
square[3][2] = 'o';
square[3][3] = 'p';
square[3][4] = 's';
square[4][0] = 't';
square[4][1] = 'u';
square[4][2] = 'v';
square[4][3] = 'w';
square[4][4] = 'x';

char * size = sizeof (square);

char input[26];
fgets(input, 26, stdin);

while (input != NULL) {

for (int i = 0; i < size; i++) {
char b;
b = square(i);

int j = 0;
for (j = 0; j < 5; j++) {

int k = 0;
for (k = 0; k < 5; k++) {

if (b == square[j][k]) {
int firstLetter = j + 1;
int secondLetter = k + 1;


printf("%d + ", secondLetter);
}


}


}

}

}


return 0;
}

prorpts git eornitage deacribing this cemit' . In the decryptioa program, you mAyassane the inpt will eonsist of the digits o-4. The program will print the decrypted message. You'll be usig the antoratie grading ript, yon't med to pprint. teeminal vsing geta. The Polybius Square Cipher This cipher,named after the ancient Greek scholar Polybius, ases a spcial key square to substitate letters from the plaintext with aumerie oles The cottets of Ille uare are 20 ltters of the alphabet arranged in some closo permutatlon. For example, Hevien the notes on strigs sd uidimensioal says that are included with this prolect. The notes on strings aso inelude Information about reading string input from a user 01 2 3 4 0lcrazy anples. int digit--0 Te omitted letter may be one that is inrnty , like zor he leter j may be emitted and eplaced by i anywhee it occs in the plaintext. In the example ahove, the square has heen generated using the ryward crazy To encipber a messapp, locate its eutry in theuatrix, then replace it with the two-dlgit coibination formed from the row index and the col dex. For example, the letter n woald beenanded as 31 becasitis in 3 and comn1 Here isexape 024040020023024011024331 To decrypt the message. simplywe each pair of cusesecutive digits as a row And coluan lookup into the square. Write two cu, polybiusFncrypt.cand polybiuaDacrypt.e that ipl- ment the phr Use the example suware given abore both programs. You doa't need to write code to generate other squares Each peogram should read a string from the wer using fgets. Reembur that the hat dharacter of the input will be a ewline In the ectypion program, you may e the put string will be co- will print the eneryptind string. The ecryption input way coutain the lette qz alloe letters

Explanation / Answer

Yes, Its better to write all variables at a beginning of block, except for

sub block level temporaty variables.

Below are the programs for encryption and decryption.

/*
file: polybiusEncrypt.c
sample input: crazvwx
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char ** argv) {

    char square[5][5];
    int size;
    char input[50];
    char b;
    int i,j,k;
    int dig1,dig2;

    square[0][0] = 'c';
    square[0][1] = 'r';
    square[0][2] = 'a';
    square[0][3] = 'z';
    square[0][4] = 'y';
    square[1][0] = 'b';
    square[1][1] = 'd';
    square[1][2] = 'e';
    square[1][3] = 'f';
    square[1][4] = 'g';
    square[2][0] = 'h';
    square[2][1] = 'i';
    square[2][2] = 'j';
    square[2][3] = 'k';
    square[2][4] = 'l';
    square[3][0] = 'm';
    square[3][1] = 'n';
    square[3][2] = 'o';
    square[3][3] = 'p';
    square[3][4] = 's';
    square[4][0] = 't';
    square[4][1] = 'u';
    square[4][2] = 'v';
    square[4][3] = 'w';
    square[4][4] = 'x';


    fgets(input, 50, stdin);    //read string from keyboard
    size = strlen(input);       //calculate its length
    if (input != NULL) {

      for ( i = 0; i < size-1; i++) {
        b = input[i];   // read letter from string

        for ( j = 0; j < 5; j++) {

          for ( k = 0; k < 5; k++) {
            if(b == 'q'){
                // if the letter is 'q' then consider it as 'i'
                // as per given in specification
                // location of i in array is [2][1], so we print it by adding 1,so 32
                // because address of 1st item in array is 00. but we print it as 11
                printf("32 ");
            }
            else if (b == square[j][k]) {
                //if input letter matches with array element
                //then print its location(j,k)
                int firstLetter = j + 1;
                int secondLetter = k + 1;
                printf("%d%d ", firstLetter, secondLetter);
                break;
            }

          }

        }

      }

    }

    return 0;
}


------------------------------------------------------

/*
file: polybiusDecrypt.c
sample input: 1112131415424344
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char ** argv) {

    char square[5][5];
    int size = sizeof(square);
    char input[50];

    int i, dig1,dig2;

    square[0][0] = 'c';
    square[0][1] = 'r';
    square[0][2] = 'a';
    square[0][3] = 'z';
    square[0][4] = 'y';
    square[1][0] = 'b';
    square[1][1] = 'd';
    square[1][2] = 'e';
    square[1][3] = 'f';
    square[1][4] = 'g';
    square[2][0] = 'h';
    square[2][1] = 'i';
    square[2][2] = 'j';
    square[2][3] = 'k';
    square[2][4] = 'l';
    square[3][0] = 'm';
    square[3][1] = 'n';
    square[3][2] = 'o';
    square[3][3] = 'p';
    square[3][4] = 's';
    square[4][0] = 't';
    square[4][1] = 'u';
    square[4][2] = 'v';
    square[4][3] = 'w';
    square[4][4] = 'x';


    fgets(input, 26, stdin);//read numeric string in array

    size = strlen(input)-1;   //calculate its length
    if(size%2==1)
        return 0; //if string size is odd means wrong input so exit

    for ( i = 0; i <size; i=i+2) {
            //read two letters from input string
            //convert it into two integers dig1, dig2
        dig1 = input[i]-48;     //convert char to its equivalent digit ( '2' into 2)
        dig2 = input[i+1]-48;
        printf("%c ",square[dig1-1][dig2-1]);
        //display the character specified by the two digits dig1, dig2
    }

    return 0;
}

--------------------------------------

Note: Question image was not clear & difficult to read, please upload clear image next time :)

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