Starting from:

$35

CIS3360 UCF - CECS Solution


Programming Assignment 1
Hill Cipher

1 Hill Cipher
In this assignment you’ll write a program that encrypts the alphabetic letters in a file using the Hill cipher where the Hill matrix can be any size from 2x2 up to 9x9. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below.
1.1 Command line parameters
1. Your program mustcompile and run from the terminalcommandline.
3. Your program should open the two files, echo the processed input to the screen, make the necessary calculations, and then output the ciphertext to the console (terminal) screen in the format described below.
4. Your program must be named pa01 for whichever language you choose. For example, pa01.c, pa01.cpp, pa01.java, pa01.py, or pa01.go.
Note
If the plaintext file to be encrypted doesn’t have the proper number of alphabetic characters to match the key size, pad the last block as necessary with the lowercase letter x. Make sure that all the input characters are lower case only.
1.2 Formats
1.2.1 Encryption Key File Formats
The encryption key file will contain a single positive integer, n where (1 < n < 10), on the first line, indicating the number of rows and columns in the encryption matrix. The following n lines will contain n integers, in each row, in order, of the encryption matrix, separated by spaces.
1.2.2 Encryption Plaintext File Formats
1.2.3 Output Format
The program must output the following to the console (terminal) screen, also known as stdout:
1. Echo the numbers from the input key file.
2. Echo the lowercase alphabetic text derived from the input plaintext file.
• Remember to pad with x if the processed plaintext does not match the block size of the key.
3. Ciphertext output produced from encrypting the input key file against the input array specified in the key file.

1.2.4 Program Execution
The program, pa01, expects two inputs at the command line.
• The first parameter is the name of the key file,which contains a single positive integer, n where (1 < n < 10), on the first line, indicating the number of rows and columns in the encryption matrix. The following n lines will contain the contents of each row, in order, of the encryption matrix, separated by spaces.
1.2.5 Program execution - example
Notethatthecommandsbelowarealsooutlinedlateroninthisdocumentforeitherc,c++,Java, Go, or Python. Also note that the first parameter is the key filename and the second parameter is the plaintext filename.
systemPrompt$ gcc -o pa01 pa01.c systemPrompt$ ./pa01 kX.txt pX.txt
A sample program execution with outputs is shown below. It is explained in more detail later on in the Section Sample inputs and outputs on page 6.
systemPrompt$./pa01 k1.txt p1.txt
Key matrix:
2 4
3 5
Plaintext:
notonlyistheuniversestrangerthanwethinkitisstrangerthanwecanthinkwernerheisenber gx
Ciphertext:
efqxsqciitepovwzytawitizyrytooaniiooqlassteocmancmgqovktqwanooqlekytqhkioaawesyt ad
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
• Program name - the program name must be pa01 in order to work with the shell scripts the graders use to grade your assignment. As mentioned before, the program must be named pa01 for whichever language you choose. For example, pa01.c, pa01.cpp, pa01.java, pa01.py, or pa01.go.
• Header - the following Header Usage instructions/comments comment block should be at the beginning of the source file.
/*============================================================================
| Assignment: pa01 - Encrypting a plaintext file using the Hill cipher |
| Author: Your name here
| Language: c, c++, Java, go, python
|
| To Compile: javac pa01.java
| gcc -o pa01 pa01.c
| g++ -o pa01 pa01.cpp
| go build pa01.go
|
| To Execute: java -> java pa01 kX.txt pX.txt
| or c++ -> ./pa01 kX.txt pX.txt
| or c -> ./pa01 kX.txt pX.txt
| or go -> ./pa01 kX.txt pX.txt
| or python -> python3 pa01.py kX.txt pX.txt
| where kX.txt is the keytext file
| and pX.txt is plaintext file
| Note:
| All input files are simple 8 bit ASCII input
| All execute commands above have been tested on Eustis
|
+===========================================================================*/
/*============================================================================= | 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. Write a section of code or function that reads only the upper and lower case letters in the input file into an char array of size 10,000, storing only the appropriate lowercase letters in the character array.
2. Write a section of code or function that takes as input the array from section 1 and the encryption key and produces an array of ciphertext storing only lowercase letters.
3. Write a section of code or function that takes as input the array storing the ciphertext and outputs it to the screen in the format specified. Additional functions or code will be needed to echo the input key and plaintext files.
1.5 Sample inputs and outputs
1.5.1 Sample Key File
2
2 4
3 5
This is k1.txt in the Programming Assignment 1 ZIP file.
1.5.2 Sample Plaintext File
"Not only is the Universe stranger than we think, it is stranger than we can think." Werner Heisenberg
This is p1.txt in the Programming Assignment 1 ZIP file.
1.5.3 Sample Ciphertext Output File
efqxsqciitepovwzytawitizyrytooaniiooqlassteocmancmgqovktqwanooqlekytqhkioaawesyt ad
1.5.4 Sample console output (stdout) systemPrompt$./pa01 k1.txt p1.txt
Key matrix:
2 4
3 5
Plaintext:
notonlyistheuniversestrangerthanwethinkitisstrangerthanwecanthinkwernerheisenber gx
Ciphertext:
efqxsqciitepovwzytawitizyrytooaniiooqlassteocmancmgqovktqwanooqlekytqhkioaawesyt ad
Notes
• The file type titles (Key matrix, Plaintext, & Ciphertext) are preceded by a newline or . Likewise after the titles, there is a newline or .
• Each 80 character plaintext or ciphertext line is likewise terminated by a newline or .
2 Matrix multiplication review
A quick review of matrix multiplication:
In mathematics, particularly in linear algebra, matrix multiplication is a binary operation that produces a matrix from two matrices. For matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the second matrix. The resulting matrix, known as the matrix product, has the number of rows of the first and the number of columns of the second matrix. The product of matrices A and B is denoted as AB. In the pseudocode below, the product AB is C.1
Remember that in the HillCipher the key matrix has the same number of columns as rows, and is also known a square matrix.

Algorithm1 MATRIX-MULTIPLY(A, B)

1: if A.columns 6= B.rows then
2: error incompatible dimensions
3: else
4: let C be a new A.rows X B.columns matrix
5: for i = 1 → A.rows do
6: for j = 1 → B.columns do
7: ci j = 0
8: for k = 1 → A.columns do

2.1 Grading
Scoring will be based on the following rubric:
Table 2.1: Grading Rubric
Deduction Description
-100 Cannot compile on eustis
-100 Your program does not successfully compile from the command line with one of these commands:
C program: systemPrompt$gcc -o pa01 pa01.c
C++ program: systemPrompt$g++ -o pa01 pa01.cpp
Go program: systemPrompt$go build pa01.go
Python program: systemPrompt$python3 pa01.py Java program: systemPrompt$javac pa01.java
Note:
IfyouaresubmittingaJavaprogram,theclassfilemustbenamed“pa01.java” and the class name must be “pa01”.
If you are submitting a Python program, the version of Python running on Eustis is Python 3.
-100 Cannot read input files specified on command line
-100 Program source filename is not pa01 with the appropriate language extension of .c, .cpp, .java, .go or .py.
-100 Cannot write output to stdout
- 90 Your program does not run from the command line without error or produces no output.
- 70 The program compiles, runs, and outputs the key and input file, but crashes thereafter or produces no encryption output.
- 50 Runs without crashing but produces nomeaningful encryption output
- 20 Fails to produce valid square matrix key based on the input key file
- 20 Fails to produce valid all lowercase alphabetic plain text - formatted to 80 columns per line
- 25 Does not have Header Usage instructions/comments statement

More products