Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please read through all below and follow the specifications exactly. PLEASE include comments so that I may understand the code as I am trying to

Please read through all below and follow the specifications exactly. PLEASE include comments so that I may understand the code as I am trying to learn. Please make as simple as possible. Thank you!

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 must name the class Vigenere

Requirements Specification

For this program:

The user will input a string containing a message of several words and punctuation.

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.

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

Add the ciphertext character 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 void

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions