Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 4, Problem 11PP

Your country is at war and your enemies are using a secret code to communicate with one another. You have managed to intercept a message that reads as follows:

:mmZ\dxZmx] Zpgy

The message is obviously encrypted using the enemy’s secret code. You have just learned that their encryption method is based upon the ASCII code (see Appendix 7). Individual characters in a string are encoded using this system. For example, the character ‘A’ is encoded using the number 65 and ‘B’ is encoded using the number 66. Your enemy’s secret code takes each letter of the message and encrypts it as follows:

if (OriginalChar + Key > 126) then

EncryptedChar = 32 + ((OriginalChar +Key) − 127)

else

EncryptedChar = (OriginalChar + Key)

For example, if the enemy uses Key = 10 then the message “Hey” would initially be represented as:

Character    ASCII code

H    72.

e    101

y    121

And “Hey” would be encrypted as:

Encrypted H − (72 + 10) − 02 − R in ASCII

Encrypted e − (101 + 10) – 111 − o in ASCII

Encrypted y = 32 + ((121 + 10) − 127) = 36 = $ in ASCII

Consequently, “Hey” would be transmitted as “Ro$.” Write a Java program that decrypts the intercepted message. You only know that the key used is a number between 1 and 100. You can assume that the original message consists entirely of ASCII codes that represent only printable characters. Your program should try to decode the message using all possible keys between 1 and 100. When you try the valid key, the message will make sense. For all other keys, the message will appear as gibberish. Since there are only 100 keys this would obviously be a pretty crummy encryption system. This Programming Project will require you to explore a bit on your own how to convert from a char to a number, process the number, then convert it back to a char. See Chapter 2 for String methods.

You will want to use charAt ().

Important: Note that the secret code has a \ so you will need to escape encode it by using \\ if you hard-code it in your program.

Blurred answer
Students have asked these similar questions
Encryption is commonly used to disguise messageson the internet. A Caesar cipher performs a shift ofall of the characters in a string (based on their ASCIIvalues, see Table 2.1), e.g.h e l l o → m j q q tThe example shows a shift with a distance of 5characters, i.e. h(ASCII:104) → m(ASCII:109)Write a C/C++ program that asks the user to input aline of plaintext and the distance value and outputsan encrypted text using a Caesar cipher, with theASCII values range from 0 through 127. Useunderscores (ASCII: 95) to represent spacecharacters.Underscore characters should not be encrypted,and any character that is encrypted may notbecome an underscore. In this case, the charactershould be changed to the next character in theASCII table.The program should work for any printablecharacters.NB: No strings (datatype) or library functions maybe used.See Figure 2.1 for example output.
I need help in solving the following question using C(NOT C++ OR C*) without using strings or arrays. The Ceaser cipher is one of the simplest and widely known encryption technique. It works by shifting each character with a constant number of places. For simplicity, and because we don’t do String manipulations here, you simply have to implement it with numbers. Given a number N, and shift S, you are to shift each digit of N S number of places to the right of the number line.   N (Plain text): 19085 S (Shift): 3 Ciphered:       42318
Encryption is commonly used to disguise messages on the internet. A Caesar cipher performs a shift of all of the characters in a string (based on their ASCII values, see Table 2.1), e.g. h e l l o → m j q q tThe example shows a shift with a distance of 5characters, i.e. h(ASCII:104) → m(ASCII:109)Write a C/C++ program that asks the user to input a line of plaintext and the distance value and outputs an encrypted text using a Caesar cipher, with the ASCII values range from 0 through 127. Use underscores (ASCII: 95) to represent space characters.Underscore characters should not be encrypted, and any character that is encrypted may not become an underscore. In this case, the character should be changed to the next character in the ASCII table.The program should work for any printable characters.NB: No strings (datatype) or library functions may be used.See Figure 2.1 for example output.

Chapter 4 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Ch. 4.1 - Prob. 11STQCh. 4.1 - Write a for statement that displays the even...Ch. 4.1 - Prob. 13STQCh. 4.2 - Write a Java loop that will display the phrase One...Ch. 4.2 - Write a Java loop that will set the variable...Ch. 4.2 - Write a Java loop that will read a list of numbers...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - Revise the loop shown in Listing 4.6 to use a...Ch. 4.2 - What is the bug in the code in the section Tracing...Ch. 4.2 - Add some suitable output statements to the...Ch. 4.2 - What is the bug in the code in the previous...Ch. 4.2 - Prob. 24STQCh. 4.2 - Suppose that you did not have assertion checking...Ch. 4.3 - Prob. 26STQCh. 4 - Write a fragment of code that will read words from...Ch. 4 - Develop an algorithm for computing the...Ch. 4 - Develop an algorithm for a simple game of guessing...Ch. 4 - Write a fragment of code that will compute the sum...Ch. 4 - Convert the following code so that it uses nested...Ch. 4 - Write a for statement to compute the sum 1 + 22 +...Ch. 4 - (Optional) Repeat the previous question, but use...Ch. 4 - Write a loop that will count the number of blank...Ch. 4 - Write a loop that will create a new string that is...Ch. 4 - Write a program that will compute statistics for...Ch. 4 - Suppose we attend a party. To be sociable, we will...Ch. 4 - Define an enumeration for each of the months in...Ch. 4 - Write a fragment of code that computes the final...Ch. 4 - Suppose that you work for a beverage company. The...Ch. 4 - Suppose that we want to compute the geometric mean...Ch. 4 - Prob. 16ECh. 4 - Create an applet that draws a pattern of circles...Ch. 4 - Prob. 18ECh. 4 - What does the following fragment of code display?...Ch. 4 - Repeat Practice Program 4 of Chapter 3, but use a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Repeat Practice Program 5 of Chapter 3, but use a...Ch. 4 - Write a program to read a list of nonnegative...Ch. 4 - Write a program to read a list of exam scores...Ch. 4 - Combine the programs from Programming Projects 5...Ch. 4 - Write a program that simulates the Magic 8 Ball...Ch. 4 - Whats for dinner? Let the computer decide. Write a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Prob. 2PPCh. 4 - Write a program that reads a bank account balance...Ch. 4 - Modify Programming Project 5 from Chapter 2 to...Ch. 4 - Write a program that asks the user to enter the...Ch. 4 - Write a program that simulates a bouncing ball by...Ch. 4 - You have three identical prizes to give away and a...Ch. 4 - Prob. 9PPCh. 4 - Holy digits Batman! The Riddler is planning his...Ch. 4 - Your country is at war and your enemies are using...Ch. 4 - Prob. 12PPCh. 4 - Prob. 13PPCh. 4 - Prob. 14PPCh. 4 - (Challenge) Repeat the previous project, but...Ch. 4 - Write a JavaFx application that displays a series...

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
What type of program do you use to write Java source code?

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

(Largest row and column) Write a program that randomly fills in 0s and l s into a 4-by-4 matrix, prints the mat...

Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges; Author: FreecodeCamp.org;https://www.youtube.com/watch?v=oBt53YbR9Kk;License: Standard YouTube License, CC-BY