Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming! Java! Java! Java! Your country is at war and your enemies are using a secret code to communicate with each other. You have

Java Programming! Java! Java! Java!

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

:mmZ\dxZmx]Zpgy

Message is encrypted using the enemy's secret code. You have just learned that their encryption method is based upon the ASCII code. Refer to Appendix 3 Page 1018 in the ecopy of the textbook under Chapter 1.

Individual characters in a string are encoded using this system. For example, the letter "A"is encoded using the numbers 65 and "B" is encoded using the numbers 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 be encrypted as:-

Character ASCII Code

H 72

e 101

y 121

Encrypted H = (72 + 10) = 82 = R in ASCII

Encrypted e = (101 + 10) = 111 = o in ASCII

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

Consequently, "Hey" would be translated as "Ro$" in ASCII

Write a program that decrypts the intercepted message. The ASCII codes for the unencrypted message are limited to the visible ASCII characters. You only know that the key used is a number between 1 and 100. 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.

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

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions