Question: Having issues compliling this C program. It should read input from a file, a string of 16 characters, followed by a newline, followed by some
Having issues compliling this C program. It should read input from a file, a string of 16 characters, followed by a newline, followed by some data to 'encrypt'. This string should be put into a two-dimensional array.
Suppose that I have a table that is 4x4 tiles. Each tile is actually a wiring diagram. Take a look at the following picture:

So assume that I have a byte, which is of course eight bits. Bit zero is at the far right and bit seven at the far left this is just how these things are numbered. If I feed the byte into the top of the diagram, then after a bit of back-and-forth youll see that bit 7 ends up coming out at bit 6, and bit 6 ends up coming out at bit 7. Similarly, 5 and 4 are swapped, and 3 and 2 are swapped. But bit 1 comes out in the same spot (after several back-and-forth) and so does bit 0. We can see that a binary 10101010 would appear at the bottom as 01010110. Or in hex, 0xAA ends up as 0x56.
Say I rotate the entire table 90 degrees left:

In this case, of course, my 0xAA which is 10101010 comes out as 01101010 which is 0x6A. If I do it again I get this:

Here if I give it 0xAA I get out 0x95. One more rotation, and then one more after that:

And just for the record, putting 10101010 into the third one gives 10101001, and handing 10101010 to the fourth one gives 01010110 as expected, since we are starting over. (When you rotate the fourth time, youll see that you end up with the original diagram. Oh well.) What we will use this for is to perform very bad encryption.
One other thing I would like to point out is that if the table is in a certain position, putting in some value, say A, and ending up with some value B implies that if I put in B I get out A. Our data consists of a string of 16 characters, followed by a newline, followed by the data that is to be encrypted. These first characters are either S which indicates that the bits are swapped, or N which indicates that they are not. Going back to Figure 1 (or the right diagram in Figure 4) the data would be SNSSNSNSSNNSSNNS. We could thus put this into a two-dimensional array:
S N S S
N S N S
S N N S
S N N S
Encrypting one byte can be done something like this:
for( col = 0; col
and so on. Pretty soon you may realize that another method is to just know the count of S in the column and if the count is an odd number, swap. Dont do it this way please.
Finally, before we get to the specifics of the assignment, let me point this out one more time. If I feed 10101010 into Figure 1 and get 01010110 out, this implies that feeding Figure 1 the input 01010110 gives me back the original 10101010. After all, some we are swapping, and we certainly can swap them back, right?
Your assignment is as follows:
Accept as input from stdin a file of data. Please do not open a file, just read from the standard input. The first 16 bytes are as described above. After this initial string there is a newline character, and then the data to encrypt. You can read these (and everything else) with getchar, and print everything with just putchar.
Output the original 16 bytes as well as the newline character.
For each byte of the rest of the data, encrypt the byte and print it, then after each byte rotate the table left as shown above.
Repeat this byte by byte until you encounter the end of the file.
You must use the following functions for this assignment:
o main in charge of running the program.
o rotate it takes one parameter, the 4x4 table, and rotates it 90 degrees left. It is a void function.
o encrypt it takes two parameters, the character to encrypt and the table. It returns a char as the result.
Also, please name your program file tablecrypt.c and your executable tablecrypt.
Include the C source code obviously but also the Makefile.
Figure 1: Table Wiring Diagram Figure 1: Table Wiring Diagram
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
