SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Strings And Vectors
Exercise:
Programming Projects
Question:12 | ISBN:9780321531346 | Edition: 7

Question

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

CHAPTER 8 / Strings and Vectors

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. Appendix 3 shows the ASCII character set. Individual characters in a string are encoded using this system. For example, the letter “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 be

encrypted as:

C__h_a_r_ac_t_e_r____A_S_C_I_I_ c_o_d_e__

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 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 1 and 100.

When you try the valid key, the message will make sense. For all other

keys, the message will appear as gibberish.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.