In this Java Program 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. 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. 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.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 The file to be encrypted can be any valid text file with no more than 9, 991 letters in it. (Thus, it’s safe to store all characters in the file in a character array of size 10, 000, including 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 A and a the same in your program. Remember that the input plaintext file may need to be padded to match the block size of the key. 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. The output portion of the input plaintext file should consist of only lowercase letters in rows of exactly 80 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. 1.2.4 Program Execution The program, 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. • The second parameter is the name of the plaintext file, note that this input files may contain non-alphabetic characters (numbers, punctuation, white spaces, etc.). The valid inputs, as discussed previously, may be any alphabetic character, and should be converted to low

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In this Java Program 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.

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.

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.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
The file to be encrypted can be any valid text file with no more than 9, 991 letters in it. (Thus,
it’s safe to store all characters in the file in a character array of size 10, 000, including 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 A and a the same in your program.
Remember that the input plaintext file may need to be padded to match the block size of the
key.

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.

The output portion of the input plaintext file should consist of only lowercase letters in rows of
exactly 80 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.

1.2.4 Program Execution
The program, 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.

• The second parameter is the name of the plaintext file, note that this input files may
contain non-alphabetic characters (numbers, punctuation, white spaces, etc.). The valid
inputs, as discussed previously, may be any alphabetic character, and should be
converted to lower case.
 
```plaintext
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:
notonlyistheuniversestrangerthanwethinkitisstrangerthanwecanthinkwernerheisenbergx

Ciphertext:
efqxsqciitepovwzytawitizyrvtooaniiioqllasteocmamcmgqovktqwanooqlekytqhkioaawesytad
```

### Description

This segment provides a demonstration of compiling and running a C program that encrypts a given plaintext using a specific key matrix. The example describes compiling the program using GCC and then executing it with specific input files.

- **Compilation Command:** 
  - `gcc -o pa01 pa01.c` compiles the program.
  
- **Execution Command:**
  - `./pa01 kX.txt pX.txt` runs the executable with input files for the key and plaintext.

- **Key Matrix:**
  - Displays a 2x2 matrix used for the encryption:
    ```
    2   4
    3   5
    ```

- **Plaintext:**
  - The original message to be encrypted:
    ```
    notonlyistheuniversestrangerthanwethinkitisstrangerthanwecanthinkwernerheisenbergx
    ```

- **Ciphertext:**
  - The encrypted output generated by the program:
    ```
    efqxsqciitepovwzytawitizyrvtooaniiioqllasteocmamcmgqovktqwanooqlekytqhkioaawesytad
    ```

The example provides an insight into how plaintext is transformed into ciphertext using matrix manipulation, a fundamental concept in cryptography.
Transcribed Image Text:```plaintext 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: notonlyistheuniversestrangerthanwethinkitisstrangerthanwecanthinkwernerheisenbergx Ciphertext: efqxsqciitepovwzytawitizyrvtooaniiioqllasteocmamcmgqovktqwanooqlekytqhkioaawesytad ``` ### Description This segment provides a demonstration of compiling and running a C program that encrypts a given plaintext using a specific key matrix. The example describes compiling the program using GCC and then executing it with specific input files. - **Compilation Command:** - `gcc -o pa01 pa01.c` compiles the program. - **Execution Command:** - `./pa01 kX.txt pX.txt` runs the executable with input files for the key and plaintext. - **Key Matrix:** - Displays a 2x2 matrix used for the encryption: ``` 2 4 3 5 ``` - **Plaintext:** - The original message to be encrypted: ``` notonlyistheuniversestrangerthanwethinkitisstrangerthanwecanthinkwernerheisenbergx ``` - **Ciphertext:** - The encrypted output generated by the program: ``` efqxsqciitepovwzytawitizyrvtooaniiioqllasteocmamcmgqovktqwanooqlekytqhkioaawesytad ``` The example provides an insight into how plaintext is transformed into ciphertext using matrix manipulation, a fundamental concept in cryptography.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education