User Tools

Site Tools


Sidebar

projects

  • cci0 (due 20150128)
  • mms0 (due 20150204)
  • mbe0 (due 20150211)
  • mbe1 (due 20150311)
  • afn0 (due 20150318)
  • cbf0 (due 20150408)
  • EoCE - bottom of your Opus (due 20150514 by 4:30pm)
haas:spring2015:cprog:projects:cbf0

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, 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.

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:

  • The last twelve consecutive 12 bytes (in incrementing order) of cbf0.jpg are the first twelve consecutive bytes of out.file
  • The next previous twelve consecutive 12 bytes (in incrementing order) of cbf0.jpg are the next twelve consecutive bytes of out.file
  • and so on until the file is “reversed”, in units of 12 byte chunks (the individual bytes of the chunks have not had their order changed)

Your task is to write a C program that does the following:

  • opens and reads out.file
  • caches its entire contents in an array (don't waste space! use appropriately-sized data types)
  • once loaded into memory, close out.file and open a new file for writing
    • that new file will be called /home/username/public_html/cbf0.jpg (where “username” is your lab46 username)
  • do the necessary processing to unscramble (unreverse) the reversed data, being mindful of those 12 byte chunks, to restore the original cbf0.jpg file in its specified location.
  • once done, don't forget to close the file you had opened for writing

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).

Submission

To successfully complete this project, the following criteria must be met:

  • Code must compile cleanly (no warnings or errors)
  • Final image must be viewable.
  • Code must be nicely and consistently indented (you may use the indent tool)
  • Code must utilize the specifications presented above
  • Code must be commented
    • have a properly filled-out comment banner at the top
    • have at least 20% of your program consist of //-style descriptive comments
  • Track/version the source code in a repository
  • Submit a copy of your source code to me using the submit tool.
    • You are to submit 3 files:
      • your C source code to accomplish this task
      • your copy of out.file
      • your processed cbf0.jpg file

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.

haas/spring2015/cprog/projects/cbf0.txt · Last modified: 2015/03/22 15:15 by wedge