Question: . Use the file attached and complete the following two methods: * encode(String p, String key) that takes a plain text p and encodes it

. Use the file attached and complete the following two methods:

* encode(String p, String key) that takes a plain text p and encodes it to a cipher text by adding the key values to each alphabet character of p, (For example, if p = "attack at dawn" and key is "two", it should be encrypted as "uphuzztxht ppj" because

'a'+'t' = 1+20 = 21 = 'u',

't'+'w' = 20+23 = 16 = 'p',

't'+'o' = 20+15 = 8 = 'h',

'a'+'t' = 1+20 = 21 = 'u',

'c'+'w' = 3+23 = 26 = 'z',

'k'+'o' = 11+15 = 26 = 'z',

' '+'t' = 0+20 = 20 = 't',

'a'+'w' = 1+23 = 24 = 'x',

't'+'o' = 20+15 = 8 = 'h',

' '+'t' = 0+20 = 20 = 't',

'd'+'w' = 4+23 = 0 = ' ',

'a'+'o' = 1+15 = 16 = 'p',

'w'+'t' = 23+20 = 16 = 'p', and

'n'+'w' = 14+23 = 10 = 'j'.)

Note that ' ' = 0, 'a' = 1, 'b' = 2, 'c' = 3, , 'z' = 26.

* decode(String c, String key) that takes a cipher text c and decodes it to a plain text by subtracting the key values from each alphabet character of c.

Assume that the only characters allowed in the plain text are lower-case alphabet letters and blanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!