Given an arbitrary text file, your program will pack the ascii code characters into integers. Specifically, 4 characters will be encoded into one unsigned integer. Then, you save your integers into a binary file. If you want, as an option, you can modify your integer by adding a number k or shifting it k bits in circle; k is the shared key between you and your partner. Then, your partner's program will read the binary file, and decode the contents into the original text, and save the text in a text file.
Here are some basic components for your program design. To simplify the matter, we'll use Solution.txt as input file, Solution.bin as binary output, and Solutionc.txt as text output.
In "encoding.c", you have a function "encoding" which opens a text fiile "Solution.txt" for reading and a binary file "Solution.bin" for writing. Then, read 4 characters at a time, pack them into an integer by a function "pack", manipulate the integer by "encryption", and write the integer into "Solution.bin" until the end of "Solution.txt". At the end of file, you may save some NULL ('') characters to make it 4 characters for the integer, so you know NULL means the end of the input. Close all the files. The encryption part is optional.
In "decoding.c", you have a function "decoding" which opens "Solution.bin" for reading and a text file "Solutionc.txt" for writing. Then, read an integer at a time, use the key from your partner to manipulate the integer by a function "decryption", unpack it into 4 characters by a function called "unpack", and save the 4 characters into "Solution.txt". Close all the files. If there is no encryption, there is no decryption.
Your "main.c" is simple: display the content of "Solution.txt", call encoding, call decoding, and display the contents of "Solutionc.txt". You can display the content of a file by a system call as follows, for example: system ("cat Solution.txt");
You should have corresponding header files for compilation and linking. Again, you don't share your source code, but you share the key and the object files.
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
void unpack(char c, unsigned int i)
c = (i >> 24) & 0xFF;
c = (i >> 16) & 0xFF;
c = (i >> 8) & 0xFF;
c = i & 0xFF;
filePointerR = fopen("Solution.bin","r");
filePointerW = fopen("Solutionc.txt","w+");
while (fread(&i, sizeof(int), 1, filePointerR) == 1)
This is only a preview of the solution. Please use the purchase button to see the entire solution