Question
Goal Take a detailed requirements and system design specification and code up a small program Understand the use of methods to breakdown a problem into
Goal
Take a detailed requirements and system design specification and code up a small program
Understand the use of methods to breakdown a problem into smaller pieces to code and test
Use the Vigenere encryption algorithm to encrypt a string
Use a multidimensional array
Read this Requirements and System Design document carefully. Being able to translate this into code is an important piece of this exercise. After reading the document, if you still don't understand this lab, then please:
Read it again, more slowly (perhaps out loud).
While reading it, take notes. Writing something down often helps you to understand it better.
Email me with specific questions. Just saying "I don't understand" won't cut it.
Come to the Open Lab on Wednesday night.
Make an appointment with the lead instructor See Faculty Information
Please get advance permission to vary from this System Design, which includes method names and method signature. In any case, you must use the 2-D array for the Vigenere square, and you must code up the encryption method called encrypt and the decryption method called decrypt. Both of these methods must call at least two other methods to help perform their task. You will be using most of this code again in Project2.
Read the following documents before attempting this Lab:
LessonsProjectsQuizzes
CodeStyleGuidelines
CreateProjectPrograms
Lesson2Slides and Textbook Chapters 7-10
Worth 70% of Lab/Quiz grade.
Submission
You must name your project Lab2.
You must name the class Vigenere.
You must name the zip file Lab2.zip and submit it to Blackboard.
Do not submit any rar files.
I do not grade programs that do not compile or run.
Email me broken code all zipped up as you would submit it.
Do not submit broken code.
Requirements Specification
For this program:
The user will input a string containing a message of several words and punctuation.
2)Only the alphabetic characters in the string must be encrypted. The rest of the characters are left as is.
You must use the Vigenere encryption algorithm as described below.
The user will also enter the key needed which must contain only one word with only alphabetic characters.
The Vigenere square will only contain the lowercase letters. You should convert the message and key to lower case before the encryption.
The program will display the encrypted message.
Next, the encrypted message should be decrypted and the decrypted message should be displayed.
Background
In todays cyber world, files are encrypted and sent over the worlds networks. Cryptography is the science of making messages secure, of transforming readable messages (plaintext) into unreadable messages (ciphertext) and back again. The process of turning plaintext into ciphertext is called encryption. The reverse process is called decryption.
Most encryption schemes use an encryption key. In principle, it is possible to decrypt the message without possessing the key. But, for a well-designed encryption scheme, large computational resources and skill are required. An authorized recipient can easily decrypt the message with the key provided by the originator to recipients, but not to unauthorized interceptors.
Basic Substitution Cipher
The art of creating and sending secret messages goes back to at least the time of Caesar. The most basic encryption scheme is the substitution cipher, where one letter in the text is substituted for another. Here, the key would be the list of substitution characters. These basic substitution cipher encoded messages are fairly easy to decipher without the key using the frequency of letters in the language.
Example of Substitution Cipher:
Alphabet: abcdefghijklmnopqrstuvwxyz
Key: bpzhgocvjdqswkimlutneryaxf
Encode: waketech:ybqgngzv
Vigenere Cipher
In 1592, the Vigenere cipher was created. This Vigenere cipher encryption scheme uses a key and a matrix called the Vigenere square (the pink matrix below bounded by the green column to the left and the tan row above with the column indices in the row above the square and the row indices in the column to the left of the square). It uses multiple letter mappings, rather than one key for the whole message. By using a different key for each letter, it makes the frequency analysis much more difficult and basically useless. The Vigenere square is a simple rotation of the alphabet for each letter. The Vigenere square below is for the lowercase alphabet: (This is the one used in this lab. Project 2 will use the first 127 characters of the ASCII code)
With this algorithm, the rows are associated with the characters in the key and the columns are associated with the characters in the message to encrypt. In this lab both the message and key should be converted to lower case, but not with the Project 2. For this example of the Vigenere cipher, the key is LINKED and the message is The eagle has landed.
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
0 | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z |
1 | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | a |
2 | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | a | b |
3 | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | a | b | c |
4 | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | a | b | c | d |
5 | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | a | b | c | d | e |
6 | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | a | b | c | d | e | f |
7 | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | a | b | c | d | e | f | g |
8 | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | a | b | c | d | e | f | g | h |
9 | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | a | b | c | d | e | f | g | h | i |
10 | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | a | b | c | d | e | f | g | h | i | j |
11 | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | a | b | c | d | e | f | g | h | i | j | k |
12 | m | n | o | p | q | r | s | t | u | v | w | x | y | z | a | b | c | d | e | f | g | h | i | j | k | l |
13 | n | o | p | q | r | s | t | u | v | w | x | y | z | a | b | c | d | e | f | g | h | i | j | k | l | m |
14 | o | p | q | r | s | t | u | v | w | x | y | z | a | b | c | d | e | f | g | h | i | j | k | l | m | n |
15 | p | q | r | s | t | u | v | w | x | y | z | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o |
16 | q | r | s | t | u | v | w | x | y | z | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p |
17 | r | s | t | u | v | w | x | y | z | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q |
18 | s | t | u | v | w | x | y | z | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r |
19 | t | u | v | w | x | y | z | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s |
20 | u | v | w | x | y | z | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t |
21 | v | w | x | y | z | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u |
22 | w | x | y | z | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v |
23 | x | y | z | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w |
24 | y | z | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x |
25 | z | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y |
Example:
plaintext message: the eagle has landed.
Key: linked
l | i | n |
| k | e | d | l | i |
| n | k | e |
| d | l | i | n | k | e | . |
t | h | e |
| e | a | g | l | e |
| h | a | s |
| l | a | n | d | e | d | . |
The algorithm works as follows:
Choose a key: Say: LINKED
Convert the message and key to lowercase.
The key will be used over and over again matching the letters in the message with the letters in the key.
Find the ciphertext letter (the code letter) in the Vigenere square matrix by following the steps below:
Using the character from the key, find the row where it exists by looking down column 0 until you find the correct row.
Using the character from the plaintext message, find the column where it exists by looking across row 0 until you find the correct column.
The ciphertext character will be the one in the matrix having the row and column found above
d)Add the ciphertextcharacter to the encrypted message.
key | l | i | n |
| k | e | d | l | i |
| n | k | e |
| d | l | i | n | k | e | . |
row | 11 | 8 | 13 |
| 10 | 4 | 3 | 11 | 8 |
| 13 | 10 | 4 |
| 3 | 11 | 8 | 13 | 10 | 4 |
|
col | 19 | 7 | 4 |
| 4 | 0 | 6 | 11 | 4 |
| 7 | 0 | 18 |
| 11 | 0 | 13 | 3 | 4 | 3 |
|
msg | t | h | e |
| e | a | g | l | e |
| h | a | s |
| l | a | n | d | e | d | . |
| e | p | r |
| o | e | j | w | m |
| u | k | w |
| o | l | v | q | o | h | . |
With this example, we start at the beginning of the key at l matching it to the t in the message to encode.
We find the row for l (row 11) and the column for t (column 19).
The character at matrix [row, col] = matrix [11, 19] = e.
So, place e in the coded message.
Next we move to the i in linked and match that to h in the message to encode.
We find the row for i (row 8) and the column for h (column 7).
The character at matrix [8, 7] = p. So, place p in the coded message.
And so forth.
When we reach a character that is not an alphabetic letter, we dont encode it.
So, the blank remains a blank and the period remains a period.
When we reach the end of the key, we start back over again with the key. This happens above at the l in eagle and the a in landed.
For decryption we use the same Vigenere square and key word, but this time we are finding the plaintext.
The algorithm works as follows:
Find the ciphertext letter in the Vigenere square, using the key letter row.
In that same column, get the character at row 0, this is the plaintext letter.
Add the plaintext letter to the message.
From our example above, the encrypted message was
"epr oejwm ukw olvqoh.".
So, in the matrix, we find the letter e, in row l, look up the letter at row 0 of that column. It is a t. So, add it the plaintext message. Next, we find the p, at row i. Row 0 of that column has an h. So, now our message is th". Do this for the rest of the cipher text to get our original message.
System Design
This Vigenere class uses the main method to read in the plaintext string to be encrypted and the key to use. Both are converted to lowercase. It then creates the Vigenere square, a private static 2-D array setup as described above and declared inside the Vigenere class, but outside of the methods. Next, it calls the encrypt method passing in the string and key. The encrypt method calls other methods that help it do the encryption. The encrypt method then passes the encoded ciphertext message back to the main method where it is displayed.
You must breakdown the encrypt method into simpler tasks and create at least 2 other methods that are called from the encrypt method to do these tasks.
After the encrypted ciphertext message is displayed, the main method must call the decrypt method to convert the message back to its lowercase form.
An example of methods you could use are given below:
Method | Parameters | Description | Called From |
static String encrypt() | String message, String key | Using the key, encode the message and return the encoded message | main |
static String decrypt() | String message, String key | Using the key, decode the encoded message and return the original message in lowercase | main |
static createVigSquare () | none | Setup the Vigenere square matrix initialized with lower case letters: See the example above | main |
static int getColIndex() | char ch | Return the column index of the character, ch, in the message to be encoded | encrypt |
static int getRowIndex() | char keyCh | Return the row index of the next character, keyCh, in the key | encrypt decrypt |
static char getPlainTextChar () | int rowIndex, char ch | Return the plaintext character corresponding to the ciphertext character ch from the square | decrypt |
static void main() | String [] args | 1. Prompt the user to enter the plaintext message 2. Prompt the user to enter the key 3. Convert the message and key to lowercase. 4. Setup up the Vigenere square 5. Encrypt the plaintext message using the Vigenere square 6. Display encoded ciphertext message 7. Decrypt the ciphertext message, returning a lowercase version of the original message 8. Display the decoded plaintext message | system |
Use Sample Output Below as Guide
Enter a multi-word message with punctuation:
The eagle has landed.
Enter a single word key with no punctuation:
LINKED
The encoded message is:
epr oejwm ukw olvqoh.
The decoded message is:
the eagle has landed.
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