Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
TomDeBeauchamp
Group Title
MIT 6.189 First Week  Exercise OPT.2 – Secret Messages
in Section 3, What are we being asked to do? I understand the modulus and how it works, but I am not sure what the problem is asking.
 one year ago
 one year ago
TomDeBeauchamp Group Title
MIT 6.189 First Week  Exercise OPT.2 – Secret Messages in Section 3, What are we being asked to do? I understand the modulus and how it works, but I am not sure what the problem is asking.
 one year ago
 one year ago

This Question is Closed

TomDeBeauchamp Group TitleBest ResponseYou've already chosen the best response.0
In the problem itself it says: "We want the values of the numbers to remain between 0 and 5. To do this we will use the modulus operator. The expression x%y will return a number in the range 0 to y1 inclusive, e.g. 4%6 = 4, 6%6 = 0, 7%6 =1. " I get we might want to keep the numbers below a certain threshold, but how is the modulus helpful? And how can we be sure that we can get back to the original phrase? I will point out that I don't know much about ASCII, or any other encodings.
 one year ago

whpalmer4 Group TitleBest ResponseYou've already chosen the best response.0
All you need to know about ASCII for this is that the letters are assigned to consecutive values. So the value of ord('A') + 3 = ord('D'), just as you would expect. If you wanted to shift a character by 4, you would add 4 to the value returned by ord, but you need to keep that from going beyond the end of the alphabet. What if you took the position of the letter in the alphabet, added the shift, and then took the modulus <length of alphabet> prior to adding to the ord of 'A'?
 one year ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.0
Lo Tom, I saw you took a look at the way I did it. The version I did was a bit quick and dirty. If you look at the range of characters, you could make a way to shift only lower case to lower case, upper to upper, and so on. I just took a bit of a shortcut. To be honest, if I wanted it clean I would use an if statement with a regular expression to find capitol letters, and shift them only with the range of other capitols. Etc.
 one year ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.0
for i in range(32,127): print(str(i)+" is \""+ chr(i)+'"') For 2.x, remove the ( ) from the print. That will show you the character range(s) you are interested in.
 one year ago

eSpeX Group TitleBest ResponseYou've already chosen the best response.0
Most probably have this, but for those who do not: http://www.asciitable.com/
 one year ago

TomDeBeauchamp Group TitleBest ResponseYou've already chosen the best response.0
I think my problem has been understanding the question itself. I'd gotten this far: phrase = raw_input("Type the phrase you'd like to see encoded. ") shift = int(raw_input("Type the shift value. ")) encoded_phrase = '' for letter in phrase: ascii_code = ord(letter) + shift letter_res=chr(ascii_code) encoded_phrase += letter_res print "The encoded phrase is: " + encoded_phrase This does encode the phrase, but it uses a character set far larger than what we're after. The problem wants us to go from AZ, starting over again at A. whpalmer  Thanks for your note, I get how the modulus is important to this operation. "T" shifted 7 should be "A". 20+7 == 27. 27%26 == 1
 one year ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.0
A better way would be to take things in as numbers, toss them into a matrix, ans then use an encoding matrix to garble the numbers. The numbers could then be shipped in matrix or vector form to be rebuilt on the other end, and the inverse matrix would decode them. The process of matrix multiplication would hide common values, like the letter e.
 one year ago
See more questions >>>
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.