Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Caesar cipher is a very simple way of creating coded messages. The original cipher, attributed to Julius Caesar, involves shifting every letter in a

The Caesar cipher is a very simple way of creating coded messages. The original cipher, attributed to Julius Caesar, involves shifting every letter in a plaintext message 3 positions further down in the alphabet to get the corresponding ciphertext message. For example, a Q in the plaintext message would be shifted by three postions to become a T in the ciphertext. A plaintext message of "YAK AND ZEBRA" would be transformed to the ciphertext message "BDN DQG CHEUD". Note that letters near the end of the alphabet wrap around to the beginning (e.g. Y + 3 = B). You can, of course, perform a Caesar cipher transformation using other values than 3 for the shift. "YAK AND ZEBRA" with a shift of 4, for example, becomes "CEO ERH DIFVE". In this assignment, you will write a function that implements the Caesar cipher.
Your task
Write a program (Java) that:
Asks the user for an integer (the Caesar shift value) and a string (the plaintext),
Calls a function named caesar (see below for details) to obtain the ciphertext, and
Prints the ciphertext.
Your caesar function should look like this:
caesar(shift, plaintext):
'''Returns ciphertext obtained by transforming every letter
in the plaintext by a Caesar cipher by the specified shift.
Non-letter characters should remain unchanged in the ciphertext.'''
[Your code goes here]
return [something]
A typical session with your completed program might look like this:
prompt>
What is your plaintext? follow the elk
What shift do you want to use? 3
Your ciphertext is: iroorz wkh hon
prompt>

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

Organic Chemistry

Authors: Joseph M. Hornback

2nd Edition

9781133384847, 9780199270293, 534389511, 1133384846, 978-0534389512