Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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 up to 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.
Command line parameters
Your program must compile and run from the terminal command line.
Input the required file names as command line parameters. Your program may NOT prompt the user to enter the file names. The first parameter must be the name of the encryption key file, as described below. The second parameter must be the name of the file to be encrypted, also described below. The sample run command near the end of this
document contains an example of how the parameters should be entered and processed.
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.
Your program must be named pa for whichever language you choose. For example,
pac pajava, or papy
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 Make sure that all the input characters are lower case only.
Formats
Encryption Key File Formats
The encryption key file will contain a single positive integer, where of rows and columns in the encrpytion matrix. The following lines will contain integers, in each row, in order, of the encryption matrix, seperated by spaces.
Encryption Plaintext File Formats
The file to be encrypted can be any valid text file with no more than letters in itThus it's safe to store all characters in the file in a character array of size including any numbers any padding characters. Please note that the input text file will also generally have punctuation, numbers, special characters, and whitespace in it which should be ignored. You should also convert uppercase letters to lowercase in the input file, correspondingly lowercase letters do not need to be converted. Thus, the program will treat and the same in your program. Remember that the input plaintext file may need to be padded to match the block size of the key.
Output Format
The program must output the following to console terminal screen, also known as "stdout:"
Echo the numbers from the input key file.
Echo the lowercase toalphabetic text derived from the input plaintext file.
Also; remember to pad with x if the processed plaintext does not match the block size of the key.
Ciphertext output produced from encrypting the input file against the input array specified in the key file.
The output portion of the input plaintext file should consist of only lowercase letters in rows of exactly letters per row, except for the last row, which may possibly have fewer. These characters should correspond to the ciphertext produced by encrypting using the numbers collected from the input key file and applied as a Hill cipher, via matrix multiplication see additional notes and pseudocode at the end of the document Please note that only the alphabetic letters in the input plaintext file will be encrypted. All other characters should be ignored.
Program Execution
The program, pa expects two inputs at the command line.
The first parameter is the name of the key file,which contains a single positive integer, where on the first line, indicating the number of rows and columns in the encryption matrix. The following lines contain the contents of each row, in order, of the encrpytion matrix, seperated by spaces.
The second parameter is the name of the plaintext file, note that this input files may contain nonalphabetic characters numbers punctuation, white spaces, etc.The valid inputs, as discussed previously, may be any alphabetic character, and should be converted to lower case.
Program execution example
Note that the commands below are also outlined later on in this document for either c Java, or Python. Also note that the first parameter is the key filename and the second parameter is the plaintext filename.
systemPrompt$ gcc o pa pac
systemPrompt $ pa
A sample program execution with outputs is shown below. It is explained in more detail later on in the section sample inputs and outputs.
systemPrompt$pa ktxt ptxt
Key matrix:
plaintext:
notonlyistheuniversestrangerthanwethinkitisstrangerthanwecanthinkwernerheisenbergx
ciphertext:
efqxsqciitepovwzytawitizyrytooaniiooqlassteocmancmgqovktqwanooqlekytqhkioaawesytad
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started