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.

Solution PreviewSolution Preview

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.

decoding.c :

#include <stdio.h>
#include "encoding.h"

void unpack(char c[], unsigned int i)
c[3] = (i >> 24) & 0xFF;
c[2] = (i >> 16) & 0xFF;
c[1] = (i >> 8) & 0xFF;
c[0] = i & 0xFF;

void decoding()
char c[4];
FILE *filePointerR;
FILE *filePointerW;
int i;
int j;

filePointerR = fopen("Solution.bin","r");
filePointerW = fopen("Solutionc.txt","w+");

while (fread(&i, sizeof(int), 1, filePointerR) == 1)
unpack(c, i);...
$30.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats