anonymous
  • anonymous
week 2. Optional quest.2-Secret Messages ('create a cyclic cipher') Has anybody done this, as i'm stumped!
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
See if this makes sense. c = '' b = '' a = 'abcdefghijklmnopqrstuvwxyz' shift = 5 for i in range(0,len(a)-shift): b = b + a[i] for i in range(len(a)-shift,len(a)): c = c + a[i] b = c+b print 'ORIGINAL' print a print 'SHIFT',shift print b
anonymous
  • anonymous
I don't want to give away my answer (you learn better when you get that critical flash of insight yourself), but: 1. I did find it useful to consult the ASCII table to see the limits of the lower case and upper case characters - these are the two groups of characters you have to check against. 2. Since they are encouraging the use of the mod operator (%), I found it easiest to offset the original character from its ASCII limits to a 1-26 range to be able to use the mod operator correctly. Of course, you will then need to "de-offset" the character after you shift it to get a reasonable result. 3. My conditional loop itself is seven lines long with three checks, so it doesn't have to be long or complicated to work right. (I usually find that I have found the optimal solution to a programming task when my code is concise.) It is easy (for me) to get confused when dealing with programming constructs like ord(c) vs c itself when there are several manipulations of data, as in this project, so I find it useful to print the value of every variable when troubleshooting and to use short test strings to see how I'm coming along. Hope this is at least a bit helpful.
anonymous
  • anonymous
Thanks for the prompt responses! @algotruneman ... yes, i do see what your doing there. Different from my attempted approach ! @kenray12 ... I had an outline of the basic stuff. But the creative math logic of the modulus to account for the offset is beyond me. My learning has always been (and continues to be..) a slow, gradual slog. Flashes of inspiration are pretty much alien to my brain.. This is where i got so far. ( Constructive comments?..Any more mod hints?) def rotate(phrase,move): encoded_phrase = " " for letter in (phrase): if letter.isalpha(): if letter.isupper(): ascii_code = ord(letter) ascii_code += move elif letter.islower(): ascii_code = ord(letter) ascii_code += move encoded_phrase += chr(ascii_code) print 'The encoded phrase is:',encoded_phrase phrase = raw_input ("Enter sentence: ") shift = raw_input("Enter shift: ") rotate(phrase,int(shift)) # Thanks for your time ...Pete

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
Update: Well, after a bit of looking around on Google and experimenting with my program, i eventually got there! I have to say, i'd not have got that way of using modulo (combined with subtracting...) without some heavy hints !

Looking for something else?

Not the answer you are looking for? Search for more explanations.