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]
3 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]3 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
Which of the following tasks are suitable for creating an algorithm? Choose all that apply
Hatshy [7]

A tasks are suitable for creating an algorithm are:

  • giving directions to a location.
  • solving a math problem.
  • tracking money in a bank account.
  • tracking the number of items in inventory.

<h3>What is algorithm?</h3>

An algorithm is known to be a form of a procedure that is often employed in the act of solving a problem or carrying out a computation.

Note that in the case above, A tasks are suitable for creating an algorithm are:

  • giving directions to a location.
  • solving a math problem.
  • tracking money in a bank account.
  • tracking the number of items in inventory.

See options below

giving directions to a location

saving time writing a computer program

solving a math problem

tracking money in a bank account

tracking the number of items in inventory

Learn more about algorithm from

brainly.com/question/24953880

#SPJ1

8 0
2 years ago
Most portable devices, and some computer monitors have a special steel bracket security slot built into the case, which can be u
Artemon [7]

Answer:

Instead of using a key or entering a code to open a door, a user can use an object, such as an ID badge, to identify themselves in order to gain access to a secure area. What term describes this type of object?

Explanation:

6 0
2 years ago
According to the Center for 21st Century Skills, critical thinking ability includes all of the following skills, EXCEPT ______.
Readme [11.4K]

Answer:

communicate clearly

Explanation:

4 0
2 years ago
Create a new Java project/class called ChangeUp. Create an empty int array of size 6. Create a method called populateArray that
-Dominant- [34]
<h2>Answer:</h2><h2></h2>

//import the Random and Scanner classes

import java.util.Random;

import java.util.Scanner;

//Begin class definition

public class ChangeUp {

   

   //Begin the main method

  public static void main(String args[]) {

       //Initialize the empty array of 6 elements

      int [] numbers = new int [6];

       

       //Call to the populateArray method

       populateArray(numbers);

       

       

   } //End of main method

   

   

   //Method to populate the array and print out the populated array

   //Parameter arr is the array to be populated

   public static void populateArray(int [] arr){

       

       //Create object of the Random class to generate the random index

       Random rand = new Random();

       

       //Create object of the Scanner class to read user's inputs

       Scanner input = new Scanner(System.in);

       

       //Initialize a counter variable to control the while loop

       int i = 0;

       

       //Begin the while loop. This loop runs as many times as the number of elements in the array - 6 in this case.

       while(i < arr.length){

           

           //generate random number using the Random object (rand) created above, and store in an int variable (randomNumber)

           int randomNumber = rand.nextInt(6);

       

           //(Optional) Print out a line for formatting purposes

           System.out.println();

           

           //prompt user to enter a value

           System.out.println("Enter a value " + (i + 1));

           

           //Receive the user input using the Scanner object(input) created earlier.

           //Store input in an int variable (inputNumber)

           int inputNumber = input.nextInt();

           

           

           //Store the value entered by the user in the array at the index specified by the random number

           arr[randomNumber] = inputNumber;

           

           

           //increment the counter by 1

          i++;

           

       }

       

       

       //(Optional) Print out a line for formatting purposes

       System.out.println();

       

       //(Optional) Print out a description text

      System.out.println("The populated array is : ");

       

       //Print out the array content using enhanced for loop

       //separating each element by a space

       for(int x: arr){

           System.out.print(x + " ");

       }

   

       

  } //End of populateArray method

   

   

   

} //End of class definition

<h2>Explanation:</h2>

The code above is written in Java. It contains comments explaining the lines of the code.

This source code together with a sample output has been attached to this response.

Download java
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> java </span>
0d7446bcb6b48f78b8adbfa3da89789c.png
3 0
2 years ago
Write a short reflection piece (it may consist of three bulleted items, with one explanatory sentence) on three things you learn
nydimaria [60]

Answers

  • OS(The Operating System) sends <em>interrupts to the processor</em> to stop whatever is being processing at that moment and computer architecture send <em>data bus</em>. This bus sends<u> data between the processor,the memory and the input/output unit.</u>
  • The operating system is a low-level software that supports a <em>computer’s basic functions</em>, such as <u>scheduling tasks and controlling peripherals</u> while the computer architecture has the <em>address bus bar</em>. This bus carries <u>signals related to addresses between the processor and the memory. </u>
  • The interface between <em>a computer’s hardware and its software</em> is its Architecture while An operating system (OS) is<u> system software that manages computer hardware and software resources and provides common services for computer programs.</u>

Explanation:

In short explanation,the Computer Architecture specifically <em>deals with whatever that's going on in the hardware part of the computer system </em>while the Operating System is the computer program <em>which has been program to execute at some instances depending on the programming instructions embedded in it</em>. An example is the MS Office.

5 0
2 years ago
Other questions:
  • Connected contacts require___ to open.
    11·1 answer
  • Write a program totake a depth (in kilometers) inside the earth as input data;compute
    15·1 answer
  • GenXTech is a growing company that develops gaming applications for military simulations and commercial clients. As part of its
    9·1 answer
  • My computer have black spots and line
    7·2 answers
  • Should the existing system be replaced?This is a question that is asked during the _____ stage of the Systems Development Life C
    8·1 answer
  • Biomimicry is the term used when engineers are inspired by objects found in nature? Group of answer choices True False
    10·1 answer
  • How can a student manage time and stress for better results in school? Check all that apply. by taking breaks while studying by
    8·2 answers
  • Match the items with their respective descriptions.
    6·2 answers
  • You are reviewing the output of the show interfaces command for the Gi0/1 interface on a switch. You notice a significant number
    12·1 answer
  • You are developing a Website that is going to be viewed extensively on smartphones and tablets. Which of the following should yo
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!