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
Robert and Anne, a married couple filing jointly, have an adjusted gross income of $68,676. They claim two exemptions, and can d
artcher [175]

Answer:

the answer is B

Explanation:

Just took the test

8 0
3 years ago
Read 2 more answers
A machine is a group of mechanical devices that transfer ___ input at one device into output at another device.
Arisa [49]
Ay 
Fonsi 
DY 
Oh
Oh no, oh no
Oh yeah
Diridiri, dirididi Daddy 
GoSí, sabes que ya llevo un rato mirándote 
Tengo que bailar contigo hoy (DY) 
Vi que tu mirada ya estaba llamándome 
Muéstrame el camino que yo voy (Oh)Tú, tú eres el imán y yo soy el metal 
Me voy acercando y voy armando el plan 
Solo con pensarlo se acelera el pulso (Oh yeah)Ya, ya me está gustando más de lo normal 
Todos mis sentidos van pidiendo más 
Esto hay que tomarlo sin ningún apuroDespacito 
Quiero respirar tu cuello despacito 
Deja que te diga cosas al oído 
Para que te acuerdes si no estás conmigoDespacito 
Quiero desnudarte a besos despacito 
Firmo en las paredes de tu laberinto 
Y hacer de tu cuerpo todo un manuscrito (sube, sube, sube)
(Sube, sube)Quiero ver bailar tu pelo 
Quiero ser tu ritmo 
Que le enseñes a mi boca 
Tus lugares favoritos (favoritos, favoritos baby)Déjame sobrepasar tus zonas de peligro 
Hasta provocar tus gritos 
Y que olvides tu apellido (Diridiri, dirididi Daddy)Si te pido un beso ven dámelo 
Yo sé que estás pensándolo 
Llevo tiempo intentándolo 
Mami, esto es dando y dándolo 
Sabes que tu corazón conmigo te hace bom, bom 
Sabes que esa beba está buscando de mi bom, bom 
Ven prueba de mi boca para ver cómo te sabe 
Quiero, quiero, quiero ver cuánto amor a ti te cabe 
Yo no tengo prisa, yo me quiero dar el viaje 
Empecemos lento, después salvajePasito a pasito, suave suavecito 
Nos vamos pegando poquito a poquito 
Cuando tú me besas con esa destreza 
Veo que eres malicia con delicadezaPasito a pasito, suave suavecito 
Nos vamos pegando, poquito a poquito 
Y es que esa belleza es un rompecabezas 
Pero pa montarlo aquí tengo la piezaDespacito 
Quiero respirar tu cuello despacito 
Deja que te diga cosas al oído 
Para que te acuerdes si no estás conmigoDespacito 
Quiero desnudarte a besos despacito 
Firmo en las paredes de tu laberinto 
Y hacer de tu cuerpo todo un manuscrito (sube, sube, sube)
(Sube, sube)Quiero ver bailar tu pelo 
Quiero ser tu ritmo 
Que le enseñes a mi boca 
Tus lugares favoritos (favoritos, favoritos baby)Déjame sobrepasar tus zonas de peligro 
Hasta provocar tus gritos 
Y que olvides tu apellidoDespacito 
Vamos a hacerlo en una playa en Puerto Rico 
Hasta que las olas griten "¡ay, bendito!" 
Para que mi sello se quede contigoPasito a pasito, suave suavecito 
Nos vamos pegando, poquito a poquito 
Que le enseñes a mi boca 
Tus lugares favoritos (favoritos, favoritos baby)Pasito a pasito, suave suavecito 
Nos vamos pegando, poquito a poquito 
Hasta provocar tus gritos 
Y que olvides tu apellido (DY)
Despacito
7 0
3 years ago
A que generacion pertenecen los gadgets?
alukav5142 [94]

Answer:

English please

Explanation:

8 0
2 years ago
grow a sentence frame a small and simple sentence. then expand it. Expand this sentence -I am a gril​
AlekseyPX

Answer:

I am a young lady.

Explanation:

simply sentence or expand more:

  • I am a young lady in my teens. ​
  • I am a young woman in her twenties. ​
  • I am a twenty-year-old lady who is just starting off in life. ​
  • I am a twenty-year-old woman who is just getting her feet wet in the world. ​
6 0
3 years ago
Read 2 more answers
What are some options available when inserting an address block? Check all that apply. previewing postal code full address label
iVinArrow [24]

Answer:

A. previewing

B. postal code

C. full address

E. matching fields

F. company name

7 0
3 years ago
Read 2 more answers
Other questions:
  • Similarities between human and computer​
    12·1 answer
  • The version of Windows that first provided networking capabilities was _____.
    12·2 answers
  • Which strategy should individuals working in a diverse workplace adopt?
    13·2 answers
  • Retrieve the names of employees who work on exactly one project that is controlled by their department. (It does not matter how
    7·1 answer
  • The part of the computer that contains the brain or the Central Park nursing unit is also known as
    10·1 answer
  • 4. Computer processing work that is split between a desktop computer and a more powerful computer that processes and stores shar
    7·1 answer
  • In what way do networks help to protect data
    6·1 answer
  • Use the_____icon to insert a new record.<br><br> A. *<br> B. X<br> C. =<br> D. &amp;
    11·1 answer
  • Describe 2 health risks posed by computers
    8·1 answer
  • Pls help I will give lots of points
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!