Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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. Individual characters in a string have encoded using this system. For example, the letter "A" is encoded using the number 65 and "B" is encoded using the number 66, and so on.

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:

ASCII Conversion 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 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. Your program should try to decode the message using all possible keys between 1and 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 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 char to a number, process the number, then convert it back to a char. See Chapter 2 for Strings 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.

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

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions