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: * The last twelve consecutive 12 bytes (in incrementing order) of **cbf0.jpg** are the first twelve consecutive bytes of **cbf0.file** * The next previous twelve consecutive 12 bytes (in incrementing order) of **cbf0.jpg** are the next twelve consecutive bytes of **cbf0.file** * and so on until we reach the beginning. In other words, the file's data 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 **cbf0.file** * caches its entire contents in an array (don't waste space! use appropriately-sized data types and allocated storage) * once loaded into memory, close **cbf0.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): * From outside the LAIR: http://lab46.corning-cc.edu/~username/cbf0.jpg * If on a LAIR workstation: http://www/~username/cbf0.jpg 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: * 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 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.