Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

e.mccormick Group Title

6.189 Homework Optional Solution I will be posting some solutions to optional bit of the homework, etc. These are for people to look at, learn from, comment on, etc. I am doing these in 3.2.2, so there may be some differences. Also, I know a tad bit more than the average Python beginner, so parts of my code may seem a bit different to you. However, I will try to keep things at a level that people in the course will eventually run into what I use.

  • one year ago
  • one year ago

  • This Question is Closed
  1. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    # 6.189 Homework 1 Exercise OPT.2 – Secret Messages # A simple shift cypher # Done in Python 3.2.2 On pastebin: http://pastebin.com/PU0p47xM

    • one year ago
  2. Neec0 Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Very simple and very cool! Nice work. I was waiting to see what type of work load the MechMOOC was going to offer, and it seems it will be weekly assignments. I think I will also attempt to complete the entirety of the MIT assignments...

    • one year ago
  3. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Well, that is my second Python program... ever. I just know a good chunk of C++ and VB, as well as a little of a couple others. So rather than doing most of the hello world stuff, I am going for the harder targets. It should make interesting, and I can share what I do so that others who are taking it as a starting point can see a few other things.

    • one year ago
  4. TomDeBeauchamp Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    e, I like how you did this. I'm curious about this piece: if temp >= shift: message_out=message_out+chr(temp-shift) else: message_out=message_out+chr(temp-shift+126) why the + 126? I get that you're saying, if the digit we're iterating on is less than the shift value, message_out should have the current value less the shift value (because this is your decoding process) plus 126. I understand that if temp is less than shift, you'd have a negative number, which maybe ascii doesn't support. What's special about 126? And how does it ensure you decode correctly?

    • one year ago
  5. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    It relates to the ASCII table. Though I did see some characters pop up that I did not expect, so the ASCII handling might be different. I know 3.2.2 uses UTF8, so my encoding is probably being tweaked by that.

    • one year ago
  6. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    6.189 Homework 2, OPT.1 - Pig Latin Sentences http://pastebin.com/gfisvZqZ The "advanced" Pig Latin processor. Implemented without regex, which is a bit long because of that. As you learn, you will find that Regular Expressions, or regex, are a great way to do these things.

    • one year ago
  7. gregsmyth Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I must have missed these. Is this extra MOOC-E coursework or are you following something else?

    • one year ago
  8. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    These are in the 6.189 homework. Not specific to the MOOC. Thought it would be a good time to do some, give MOOC followers something else to look at/talk about/try etc. You can see the questions I am answering in the PDF files for the class. They are optional even in 6.189, so not exactly what everyone would do.

    • one year ago
  9. TomDeBeauchamp Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    They are the most fun though.

    • one year ago
  10. gregsmyth Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks @e.mccormick, I'll have a look

    • one year ago
  11. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Something you can do in Python easily is learn the overall goal of Python. Just type in "import this" to the interpreter and presto: >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! >>>

    • one year ago
  12. S.Campbell Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    So where is the remainder or modulus operator in your solution to 6.189 OPT.2? I think this exercise is just to get you to use that operator once. I also think that the instructions are unnecessarily confusing -- who needs to know what ASCII is? I think all that is needed is that the function ord returns sequential integers for 'a' to 'z', so then you can rely on ord('z')-ord('a')==25 (I almost said 26 :-)

    • one year ago
  13. AppylPye Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Nice work on the Secret Message Cypher! It's simple to use, and does a good job of first handling possible runtime exceptions, then checking the value of the mode variable before proceeding. It is robust in that whether the user enters a non-integer (causing an exception that is caught) or an integer not equal to 1 or 2, execution continues with the same same "Not a valid selection" message, so that the user is insulated from the distinction between a runtime exception and a value check.

    • one year ago
  14. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    I felt it was better to make something that is less likely to crash then to exactly follow the instructions. It relies upon knowing ascii rather than the mod function. Also, I did not shift things in a way where capitals remain capitals, etc. Now what is real fun is working out an extended Playfair Cypher that would include all upper and lower case, as well as punctuation, and encrypt with that. Because it would be a square array, you would have the option of anything that does 52 characters or more. 8 would be 64, so 12 punctuation characters or 2 punctuation characters and the numerals. Or 9 gets you 81, which has plenty of room for things and 10 really does it. Another interesting one is to break things up into a matrix, then use rules of matrix multiplication to encrypt. Any invertible matrix can be used for this sort of solution because what you multiply by a matrix to encode can be decoded by multiplying by the inverse.

    • one year ago
    • Attachments:

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.