Table of Contents

Corning Community College

CSCS1320 C/C++ Programming

~~TOC~~

Project: C Binary Fun (cbf0)

Objective

To practice manipulating binary data in a C program (for fun and glory).

Background

With the UNIX people exploring binary data, and using hex editors, and you being tasked with writing a hex editor (at least, in certain realities within the multiverse), 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 (or solve a whole domain of problems related to binary data) 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.

Task

On lab46, in the cbf0/ subdirectory of the CPROG Public Directory is a file called cbf0.file, a 120480 byte binary file that is essentially a scrambled JPEG file (originally called cbf0.jpg).

Your task is to write a C program to unscramble cbf0.file and return it to its image-viewable cbf0.jpg state.

Regardless of whether or not you 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 cbf0.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, and hopefully will be at least mildly humorous (that of course is optional).

Submission

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 cbf0.file /home/username/public_html/cbf0.jpg
Submitting cprog project "cbf0":
    -> cbf0.c(OK)
    -> cbf0.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.