CIS 215 C++ Programming
Programming Assignment #2
Due Date: 10/21/13
The Cyclic Redundancy Check is an algorithm that is used to find errors in data that has been stored or transmitted. Since every file or message can be thought of as a single pattern of bits it can be treated as a single large binary number. The CRC technique makes use of a polynomial divisor of length n+1 to divide the source number – discarding the quotient and using the remainder as the check sum for that message.
The result of the CRC algorithm is a check value that can be used to determine whether or not the file or message being examined is the same file or message that was used to create the check value.
For more background information on CRCs I recommend the “Painless Guide to CRC Error Detection Algorithms” by Ross Williams, which you should be able to find at http://www.ross.net/crc/download/crc_v3.txt. Note that this guide provides C language source code for 16 and 32 bit CRC implementations. You may look at that code for ideas, but you may not copy it verbatim into your assignment.
The concept of CRC error checks is easy – but it is often tricky to get the correct answer. Padding the message with zeros, and mismatches between the size of your divisor, and the fields you are considering are a frequent source of errors. Also, keep in mind that the divisor is one bit larger than the width of the field it is correcting – so a CRC-5 polynomial actually has 6 bits.
There are many polynomial divisors of different lengths used to calculate CRCs. For this assignment you should use the CRC-5-USB value (0x12).
Implement a checksum program for CRC-5-USB that accepts the name of a file from the command line and prints your signature block and the correct checksum on console standard output.
Implement a checksum program for CRC-5-USB that accepts input from console standard input and writes your signature block and the correct checksum on console standard output.
Implement a checksum program for CRC-5-USB that accepts the name of a file from the command line and prints your signature block and PASS or FAIL for a file with an appended checksum.
Run your program against testfile.txt to produce a checksum.
Run your program against the input “Four score and seven years ago” (not including the quotation marks) to produce a checksum. Confirm that the checksum you receive is 0x8.
Run your program against testfile_appended.txt to produce a PASS/FAIL result.
Run your program against testfile_appended_bad.txt to produce a PASS/FAIL result.
The checksum program should be a single program with an interface that allows the user to choose which mode it is running in (File, text, and print checksum or pass/fail).
My problem is that I have ZERO experience in programming (except for a hello world program) Everything I have read seems to be written in a foreign language. I have created a dummy user interface, but that is as far as I have been able to get. If there is someone out there that can explain this assignment to me is SIMPLE terms, that would be great!
1. How would I upload a file into the program? I have tried a few things, but it doesn't seem to work.
2. Now that I have uploaded the file, how would I convert the info in the file to binary?
3. Polynomial division: I understand what it does, but not sure how to write the code.
You don't 'upload' a file in C++ but you output or input it. But in either case, you open it. In your case if the user wants to input a file in binary mode(note a binary file must already exist in your project directory), it is done as follows:
I was able to open the file that I needed (and print the contents of the file on the screen). Now I am able to open the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
if (select == 1)//user chose option 1
cout << "Enter the name of the file including path:" << endl;//prompt for file path
string filePath; //file path variable
getline(cin, filePath); //user input
cout << line << endl;
else cout << "Unable to open file" << endl;
Now, I am lost :( I apparently need to convert the file's contents into binary and do polynomial division. not sure where to start on this one. One problem solved now though, and 3 more days to write the code.