Python Challenge -1

WARNING SOLUTIONS HERE

URL: http://www.pythonchallenge.com/pc/def/map.html

This page gives us a picture and some seemingly random text.

K -> M

O -> Q

E -> G

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.

 

Looks like a ceaser or shift cipher.

Im also aware this may not be the quickest way of getting there but its how my brain works :)

The idea is i want to increment each character by two. I start by converting each ascii character to its ordinal value incrementing by two and cahnging back to a char value.

This worked except it also converted my spaces, punctuation and didnt wrap the alphabet.

My final solution was to ignore punctuation, any ordinal lower than 48.  and if the value was y(121) or z(122) just subtract 24 to get to the right place.

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."
clear = ""
for x in text:
    if ord(x) < 48:
        clear += x
    else:
        y = ord(x) +2
        if ord(x) > 120:
            y = ord(x) -24
            clear += chr(y)
        else:
            clear += chr(y)
print "Answer: "
print clear

This printed out the following

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. usingstring.maketrans() is recommended. now apply on the url.

applying this to the url give us map -> ocr

URL: http://www.pythonchallenge.com/pc/def/ocr.html

 

 

Comments