1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
cricket20 [7]
4 years ago
14

Write a program that produces a Caesar cipher of a given message string. A Caesar cipher is formed by rotating each letter of a

message by a given amount. For example, if your rotate by 3, every A becomes D; every B becomes E; and so on. Toward the end of the alphabet, you wrap around: X becomes A; Y becomes B; and Z becomes C. Your program should prompt for a message and an amount by which to rotate each letter and should output the encoded message.

Computers and Technology
1 answer:
PilotLPTM [1.2K]4 years ago
8 0

Answer:

Here is the JAVA program that produces Caeser cipher o given message string:

import java.util.Scanner;  //to accept input from user

public class Main {  

   public static void main(String args[]) {  //start of main function

       Scanner input = new Scanner(System.in);  //creates object of Scanner

       System.out.println("Enter the message : ");  //prompts user to enter a plaintext (message)

       String message = input.nextLine();  //reads the input message

       System.out.println("Enter the amount by which by which to rotate each letter : ");  //prompts user to enter value of shift to rotate each character according to shift

       int rotate = input.nextInt();  // reads the amount to rotate from user

       String encoded_m = "";  // to store the cipher text

       char letter;  // to store the character

       for(int i=0; i < message.length();i++)  {  // iterates through the message string until the length of the message string is reached

           letter = message.charAt(i);  // method charAt() returns the character at index i in a message and stores it to letter variable

           if(letter >= 'a' && letter <= 'z')  {  //if letter is between small a and z

            letter = (char) (letter + rotate);  //shift/rotate the letter

            if(letter > 'z') {  //if letter is greater than lower case z

               letter = (char) (letter+'a'-'z'-1); }  // re-rotate to starting position  

            encoded_m = encoded_m + letter;}  //compute the cipher text by adding the letter to the the encoded message

           else if(letter >= 'A' && letter <= 'Z') {  //if letter is between capital A and Z

            letter = (char) (letter + rotate);  //shift letter

            if(letter > 'Z') {  //if letter is greater than upper case Z

                letter = (char) (letter+'A'-'Z'-1);}  // re-rotate to starting position  

            encoded_m = encoded_m + letter;}  //computes encoded message

           else {  

         encoded_m = encoded_m + letter;  } }  //computes encoded message

System.out.println("Encoded message : " + encoded_m.toUpperCase());  }} //displays the cipher text (encoded message) in upper case letters

Explanation:

The program prompts the user to enter a message. This is a plaintext. Next the program prompts the user to enter an amount by which to rotate each letter. This is basically the value of shift. Next the program has a for loop that iterates through each character of the message string. At each iteration it uses charAt() which returns the character of message string at i-th index. This character is checked by if condition which checks if the character/letter is an upper or lowercase letter. Next the statement letter = (char) (letter + rotate);   is used to shift the letter up to the value of rotate and store it in letter variable. This letter is then added to the variable encoded_m. At each iteration the same procedure is repeated. After the loop breaks, the statement     System.out.println("Encoded message : " + encoded_m.toUpperCase()); displays the entire cipher text stored in encoded_m in uppercase letters on the output screen.

The logic of the program is explained here with an example in the attached document.

You might be interested in
What does “modulate your voice” mean?
Pachacha [2.7K]
A) when u modulate some thing you vary it
5 0
3 years ago
Which of the following is not a primary environment in Autodesk Inventor? A. Parts B. Assemblies C. Animations D. Presentations
UNO [17]

I want to say it's C. Animations.

I hope this helps!

7 0
3 years ago
__________ is a strategy of using multiple types of technology that prevent the failure of one system from compromising the secu
Anastaziya [24]

Answer:

<u>Redundancy</u> is a strategy of using multiple types of technology that prevent the failure of one system from compromising the security of information.

Explanation:

Redundancy means having extra or duplicate resources available to support the main system. It is a backup or reserve system that can step in if the primary system fails. The reserve resources are redundant most of the time as they are not being used if everything is working properly.

8 0
3 years ago
In one to two sentences, describe how you would insert a row in a spreadsheet.
Over [174]

Answer:

give points pls

Explanation:

7 0
4 years ago
Read 2 more answers
Why are visually interesting effects, such as WordArt, to be used sparingly?
mrs_skeptik [129]

Explanation:

<em>Formatting</em><em> </em><em>with</em><em> </em><em>Word</em><em> </em><em>Art</em><em> </em>

<em>Standard</em><em> </em><em>formatting</em><em> </em><em>options</em><em>,</em><em> </em><em>such</em><em> </em><em>as</em><em> </em><em>bold</em><em>,</em><em> </em><em>italic</em><em>,</em><em> </em><em>and</em><em> </em><em>underline</em><em> </em><em>,</em><em> </em><em>are</em><em> </em><em>all</em><em> </em><em>Available</em><em> </em><em>on</em><em> </em><em>the</em><em> </em><em>home tab</em><em>.</em><em> </em>

<em>Word</em><em> </em><em>Art</em><em> </em><em>Styles</em><em> </em>

<em>You</em><em> </em><em>can</em><em> </em><em>find</em><em> </em><em>Word</em><em> </em><em>art</em><em> </em><em>text</em><em> </em><em>effects</em><em> </em><em>in</em><em> </em><em>the</em><em> </em><em>text</em><em> </em><em>group</em><em> </em><em>on</em><em> </em><em>the</em><em> </em><em>insert</em><em> </em><em>tab</em><em>.</em><em> </em><em>When</em><em> </em><em>you</em><em> </em><em>apply</em><em> </em><em>a</em><em> </em><em>word</em><em> </em><em>art</em><em> </em><em>text</em><em> </em><em>effect</em><em> </em><em> </em><em>,</em><em> </em><em>PowerPoint</em><em> </em><em> </em><em>2</em><em>0</em><em>0</em><em>7</em><em> </em><em>displays</em><em> </em><em>the</em><em> </em><em>format</em><em> </em><em>contextual</em><em> </em><em>tab</em><em> </em><em>under</em><em> </em><em>drawing</em><em> </em><em>tools</em><em>.</em><em> </em>

8 0
3 years ago
Read 2 more answers
Other questions:
  • Briefly explain the benefits and consequences of technology. //PLEASE ANSWER//
    9·1 answer
  • How to upgrade from office home to office professional
    13·1 answer
  • . In an if/else statement, the if part executes its statement or block if the expression
    15·1 answer
  • _____________ data is what is translated to digital format so it can be stored in a computer.
    10·1 answer
  • How do you navigate multiple computer screen at one time?
    5·1 answer
  • Does anyone know how to connect a nintendo switch to a laptop?
    10·2 answers
  • 1. What are the biggest password mistakes that people and companies make? How can you avoid those mistakes?
    11·1 answer
  • Comments should Your answer: rephrase the code it explains in English be insightful and explain what the instruction's intention
    15·1 answer
  • Random.choice will choose a number between 1 and 100. True False​
    6·1 answer
  • Marc is creating a physical design, what aspect of the design deals with the interaction between a user and data?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!