Corning Community College
CSCS1320 C/C++ Programming
~~TOC~~
To practice manipulating binary data in a C program (for fun and glory).
With the UNIX people exploring binary data, and using hex editors, and you being tasked with writing a hex editor, it only makes sense to steer some of our activities towards the manipulation of binary data as well- one cannot effectively write a hex editor if they have no idea how to work with binary data.
This project aims to ameliorate that.
Binary data merely refers to data as the computer stores it. The computer is a binary device, so its raw data (as it exists on various forms of storage and media) is often referred to as binary data, to reflect the 1s and 0s being represented.
The data we have become familiar with is textual data. We read from and write to files with the express purpose of storing text in them. And with the use of various text processing tools, we can easily manipulate these text files.
But: did you know that all text data is also binary data?
The trick to remember is that its opposite is not always tre: not all binary data is text.
The computer works in units of bytes, which these days means groups of 8-bits. C has the ability to arbitrarily read and write individual bytes of data, and we will want to make use of that to aid us in our current task.
On lab46, in /var/public/cprog/spring2015/cbf0/ is a file called out.file, a 124284 byte binary file that is essentially a scrambled JPEG file (originally called cbf0.jpg).
Your task is to write a C program to unscramble out.file and return it to its image-viewable cbf0.jpg state.
For those who are in UNIX, you are not allowed to use any of the UNIX tools to accomplish this task: you must write a C program that does all the work.
The out.file data file has been scrambled as follows:
Your task is to write a C program that does the following:
You can test the success of your program by pointing a web browser at the following URL (being mindful to substitute in your lab46 username where “username” is specified):
Note that the “~” IS very much required.
If you are successful, the image should render itself in the browser, and you should be able to recognize it (vs. it being unreadable and unrecognizable). The image is intended to be meme-like in original, and hopefully will invoke a mild sense of humor (that of course is optional).
To successfully complete this project, the following criteria must be met:
To submit this program to me using the submit tool, run the following command at your lab46 prompt:
$ submit cprog cbf0 cbf0.c out.file /home/username/public_html/cbf0.jpg Submitting cprog project "cbf0": -> cbf0.c(OK) -> out.file(OK) -> /home/username/public_html/cbf0.jpg(OK) SUCCESSFULLY SUBMITTED
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.