Starting from:

$29

Exercise 1: Simple Nybble Substitution

Exercise 1: Simple Nybble Substitution
CIS5362 

Write two programs that compile and run on sand.cise.ufl.edu. 

Program 1: target name = prog1_1
Reads from stdin, writes to stdout. 
Flags: -xin for ASCII coded hex input
    -xout for ASCII coded hex output (default)
    -bin for binary input (default)
    -bout for binary output
Description:
Reads stdin in eiher binary or ASCII-coded hexidecimal format, 
outputs the same data in either binary or ASCII-coded hexidecimal format. 
When reading ASCII-coded hexidecimal input, white space is ignored, and
any non-white space values other than 0-9, a-f, and A-F are errors. 
When writing ASCII-coded hexidecimal output, write the first byte (byte 0)
in ASCII as the hex value of the upper nybble followed by the hex value of
the lower nybble followed by a space.
Write 16 bytes in this manner to a line, followed by a newline, except
possibly for the last line which may be incomplete. 
Binary in to binary out should be the identity operation. 
Hex in to hex out should at most format the hex input as noted above, and
for hex input that is already formatted should be the identity operation. 

Program 2: target name = prog1_2
Reads from stdin, writes to stdout. 
Flags: -e for encrypt
    -d for decrypt
    -k<filename for file containing the key
    -x if the key file is in ASCII-coded hexidecimal
    -b if the key file is in binary
Description:
Reads in binary from stdin, writes in binary to stdout.
For each byte as it is read in, divide into upper nybble and lower nybble. 
For each nybble, first upper then lower, substitute the nybble according to 
the permutation given in the key file, then combine the upper and lower
substituted nybbles back into a single byte, and output that byte.
The key file is 16 nybbles long (either 8 bytes that are divided into 16
nybbles in order upper nybble byte 0, lower nybble byte 0, upper nybble byte 1,
lower nybble byte 1, etc.) or 16 ASCII-coded hexidecimal values (16 bytes
that are 0-9, a-f, or A-F). Each nybble in the key file must be unique.
Encryption:
The permutation is specified by the position of the key nybble, so that an
input nybble of 0x0 is replaced by the first nybble in the key file 
(position 0), an input nybble of 0xA is replace by the 11th nybble in the 
key file (position 10 = 0xA).
Decryption:
The permutation is the inverse of the permutation for encryption. Hence, 
the key file must be read in, then the permutation inverted before applying
the transformation. 
The program must check for error conditions (e.g., missing key file, key 
file not having a valid permutation of nybbles, etc.), and report any error
to stderr in a meaningful way, then exit with a non-zero exit code. 

Submission:
Submit 
1) a makefile for all programs and support code that makes the executables
prog1_1 and prog1_2 when "make all" is typed
2) all source code (header files, etc.)
3) README.txt file that explains the environmental expectations of the code
and lists any bugs
4) Brief textual report Report_1 in text, doc, docx, or PDF format that
reflects on how you approached the problem and how you solved any challenges,
and what you learned from the assignment.






More products