Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** * Problem 1 [30pts]. According To Historians, Julius Caesar Used The Following Encryption * Technique For Sending Messages. Given A String S And An

/** * Problem 1 [30pts]. According To Historians, Julius Caesar Used The Following Encryption * Technique For Sending Messages. Given A String S And An Integer K, Replace Every Letter By * The Letter Than Comes K Positions Later In Alphabetical Order. For Example The String Hello * With Key 5, Is Encrypted Into Mjqqt Since Letter M Is

/**

* Problem 1 [30pts]. According to historians, Julius Caesar used the following encryption

* technique for sending messages. Given a string s and an integer k, replace every letter by

* the letter than comes k positions later in alphabetical order. For example the string hello

* with key 5, is encrypted into mjqqt since letter m is the fifth letter after h and so on.

* Note that z in this case is mapped to e (since after z we go back to a). To decrypt the

* message one needs to know the key; for our example, just shift each letter by -5 positions.

* In this problem you will write a program called Cipher.java which does both encryption

* and decryption. Some examples follow

* -- Enter the text below

* Hello

* -- Enter E for Encryption, D for Decryption, X to exit: E

* -- Enter key: 5

* -- The encrypted text is below

* Mjqqt

* Now another example

* -- Enter the text below

* Mjqqt

* -- Enter E for Encryption, D for Decryption, X to exit: D

* -- Enter key: 5

* -- The decrypted text is below

* Hello

* Another example

* -- Enter the text below

* Hello

* -- Enter E for Encryption, D for Decryption, X to exit: F

* -- Input not recognized. Try again.

* -- Enter E for Encryption, D for Decryption, X to exit: X

* NOTE: You can assume that the input contain only alphabet letters, both lower case and

* upper case, space, and the usual punctuation marks {., !?}. Non alphabet characters are to

* be left unchanged. Also, you must keep the case; i.e. a lower case letter should be mapped

* to a lower case letter.

* NOTE: The key k is a positive integer. But, it can be a large number. In this case, you

* must wrap it around. For example if the key is 27 then a is mapped to b etc. Your code is

* expected to work with any non-negative integer. Please check that input key is valid (that

* is key 0; if not print an error message and exit).

*/

public class Problem1 {

// start your code here

}

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

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago