Python Challenge level 1: “what about making trans?”

Level 1 gets a bit more interesting.
Hint 1: k->m, o->q, e->g

import string
src = string.lowercase[:26]
dst = string.lowercase[2:26] + 'ab'
trans = string.maketrans(src, dst)
text = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr
        amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr
        ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.
        kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
print text.translate(trans)

That gives:

i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that’s why this text is so long. using string.maketrans() is recommended. now apply on the url.

Ha, funny! Ok then, an extra:

print "map".translate(trans)

ocr

That gets us to Level 2.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

1 Comment »

 
  • Doggerel King says:

    I have fiddled with Python a couple of times in the past. Today I decided to play with it a bit more. Tackled Challenge 1. Because of my interest in the history of cryptography, I recognized it as a simple Caesar cypher pretty much from the git.

    I started out with the shift right by 2 <> then added a couple of special cases and ended up with this.

    ** Code **
    for char in inString:
    if char in ” .’”:
    newString += char
    elif char == “y”:
    newString += “a”
    elif char == “z”:
    newString += “b”
    else:
    newString += chr(ord(char) + 2)

    print newString

    It was fun.

    Now I suppose that I will have to get figure out how to use string.maketrans. Then I suppose that I will move on to Challenge 2.

 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>