Programming Assignment 2
8, 16, & 32 bit checksums
1 Checksum
In this assignment you’ll write a program that calculates the checksum for the text in a file. Your program will take two command line parameters. The first parameter will be the name of the input file for calculating the checksum. The second parameter will be for the size of the checksum (8, 16, or 32 bits). The program must generate output to the console (terminal) screen as specified below.
1.1 Command line parameters
1. Your program must compile and run from the command line.
3. Your program should open the input text files, echo the processed input to the screen, make the necessary calculations, and then output the checksum to the console (terminal) screen in the format described below.
Note
All of the test data files contain a termination character LF represented as a hexadecimal ’0A’. This character is included in all the checksum calculations.
1.2 Checksum size
The checksum size is a single integer, passed as the second command line argument. The valid values are the size of the checksum, which can be either 8, 16, or 32 bits. Therefore, if the second parameter is not one of the valid values, the program should advise the user that the value is incorrect with a message formatted as shown below:
fprintf(stderr, "Valid checksum sizes are 8, 16, or 32
");
The message should be sent to STDERR .
1.2.1 Format of the input file
The input file specified as the first command line argument, will consist of the valid 8 bit ASCII characters normally associated with the average text file. This includes punctuation, numbers, special characters, and whitespace.
1.2.2 Output Format
The program must output the following to the console (terminal) screen, also known as STDOUT: 1. Echo the text from the input file.
3. Print the checksum.
4. The checksum line should be formatted as follows :
printf("%2d bit checksum is %8lx for all %4d chars
", checkSumSize, checksum, characterCnt);
1.3 Submission instructions
You must submit this assignment in Webcourses as a source file upload. Note that all submissions will be via Webcourses. The submitted programs will be tested and graded on
Eustis.
1.3.1 Code Requirements
• Header - the following Header Usage instructions/comments comment block should be at the beginning of the source file.
/*=============================================================================
| Assignment: pa02 - Calculating an 8, 16, or 32 bit
| checksum on an ASCII input file
|
| Author: Your name here
| Language: c, c++, Java, GO, Python
|
| To Compile: javac pa02.java
| gcc -o pa02 pa02.c
| g++ -o pa02 pa02.cpp
| go build pa02.go
| python pa02.py //Caution - expecting input parameters
|
| To Execute: java -> java pa02 inputFile.txt 8
| or c++ -> ./pa02 inputFile.txt 8
| or c -> ./pa02 inputFile.txt 8
| or go -> ./pa02 inputFile.txt 8
| or python-> python3 pa02.py inputFile.txt 8
| where inputFile.txt is an ASCII input file
| and the number 8 could also be 16 or 32
| which are the valid checksum sizes, all
| other values are rejected with an error message
| and program termination
|
| Note: All input files are simple 8 bit ASCII input
|
|
+=============================================================================*/
/*============================================================================= | I [your name] ([your NID]) affirm that this program is
| entirely my own work and that I have neither developed my code together with | any another person, nor copied any code from any other person, nor permitted
| my code to be copied or otherwise used by any other person, nor have I
+============================================================================*/
1.4 Program Notes and Hints
One possible breakdown to solve this problem is as follows:
1. Collect the command line input arguments and print them to the console. Remember to remove or comment out this test code when running the testing scripts.
2. Read the file and print it out to the console.
3. Adjust the output to print 80 characters per line.
4. Calculate the 8 bit checksum. Remember that the checksum is a running total with no overflow.
5. Resolve the calculations and padding for both 16 and 32 bit checksums.
1.5 Grading
Scoring will be based on the following rubric:
Table 1.1: Grading Rubric
Deduction Description
-100 Cannot compile on eustis
-100 Program source filename is not pa02 with the appropriate language extension of .c, .cpp, .java, .go or .py.
-100 Your program does not successfully compile from the command line with one of these commands:
C program: prompt$gcc -o pa02 pa02.c C++ program: prompt$g++ -o pa02 pa02.cpp go: prompt$go build pa02.go python: prompt$python3 pa02.py Java program: prompt$javac pa02.java Note:
• If you are submitting a Java program, the class file must be named “pa02.java” and the class name must be “pa02”.
• If you are submitting a Python program, the version of Python running on Eustis is Python 3.
• Make sure to submit all your code in a single source file.
-100 Cannot read input parameters specified on command line
-100 Cannot write output to stdout
- 90 The program does not run from the command line without error or produces no output.
- 70 The program compiles, runs, and outputs the input file, but crashes thereafter or produces no checksum output.
- 50 Cannot write output to stderr
- 20 Fails to produce valid 8 bit checksum
- 20 Fails to produce valid 16 bit checksum
- 20 Fails to produce valid 32 bit checksum
- 25 Does not have Header Usage instructions/comments statement
1.6 Testing
1.6.1 Baseline
There are 5 baseline files included in the ZIP file. (Additional test files are described in the next section.) The filename and their corresponding checksums are shown in the table below:
Table 1.2: Baseline Test Schema
Filename 8 bit checksum 16 bit checksum Pad 32 bit checksum Pad Input (hex)
i1.txt 6b 610a - 610a5858 XX 610a
i2.txt cc 6bb9 X 61610a58 X 61610a
i3.txt 2d c26b - 6161610a - 6161610a
i4.txt 8e cd1a X 6bb9b9b9 XXX 616161610a
i5.txt ef 23cc - c26bb9b9 XX 61616161610a
Results were obtained using the command: bash basetest.sh pa02.|c|cpp|java|py
1.7 Testscript output
This script (pa02test.sh) is run on Eustis or other bash supported terminal command lines as shown below. Successful output is also shown below.
./pa02test.sh pa02.java
Compile of pa02 succeded.
-> Case #1 - in10A.txt - 8 bit checksum -> Case #1 - in10A.txt - 16 bit checksum
-> Case #1 - in10A.txt - 32 bit checksum -> Case #2 - in17A.txt - 8 bit checksum -> Case #2 - in17A.txt - 16 bit checksum
-> Case #2 - in17A.txt - 32 bit checksum -> Case #3 - in18A.txt - 8 bit checksum -> Case #3 - in18A.txt - 16 bit checksum
-> Case #3 - in18A.txt - 32 bit checksum -> Case #4 - inRF2.txt - 8 bit checksum -> Case #4 - inRF2.txt - 16 bit checksum
-> Case #4 - inRF2.txt - 32 bit checksum -> Case #5 - inWC2.txt - 8 bit checksum -> Case #5 - inWC2.txt - 16 bit checksum
-> Case #5 - inWC2.txt - 32 bit checksum
Checksum testing completed
1.7.1 Advanced Testing
There are eight input test files of significantly more varied content than used in the Baseline Test Schema shown above.
1. Every input file has a single line of text terminated by the hexadecimal character ’0A’ or the NEWLINE character.
2. Some input files are less than 80 characters long, others aren’t.
3. More testing files are supplied than are used in the pa02test.sh script.
4. After uploading the testing shell script (and corresponding files) remember to execute the command chmod +x *.sh to grant execution privileges for the script.
5. The script is executed at the command line by the command bash pa02test.sh pa02.c or ./pa02test.shpa02.c where the checksum program filename has the correct extension for your submission. Valid extensions are .c for C, .cpp for C++, .java for Java, .go for Go, and .py for Python.
1.7.2 Simple test cases
1. simple input files
a) i1.text contains a single lowercase a followed by the hexadecimal character ’0A’ or the NEWLINE character.
i. All three possible checksum sizes would output as shown below: hw/pa2$java pa02 i1.txt 8 a
8 bit checksum is 6b for all
hw/pa2$java pa02 i1.txt 16 a 2 chars
16 bit checksum is 610a for all hw/pa2$java pa02 i1.txt 32
a XX 2 chars
32 bit checksum is 610a5858 for all hw/pa2$ 4 chars