Saturday, 23 April 2011

Python Challenge #001 - 274877906944

What about making trans?
Examining the page source reveals a Caesar Cipher. Get the mission HTML data with urlopen.
>>> from urllib.request import urlopen
>>> CHALLENGE_URL = 'http://www.pythonchallenge.com/pc/def/map.html'
>>> text = urlopen(CHALLENGE_URL).read()
Create a translation table to shift each lower case ASCII byte by 2 places cyclically.
>>> lower = bytes(i for i in range(97, 123))
>>> lower
b'abcdefghijklmnopqrstuvwxyz'
>>> t = bytes.maketrans(lower, lower[2:] + lower[:2])
Find the enciphered text.
>>> start = text.index(b'g fmnc')
>>> stop = start + text[start:].index(b'\n')
>>> enc = text[start:stop]
>>> enc[:20]
b'g fmnc wms bgblr rpy'
Translate enciphered text.
>>> enc[:38].translate(t)
b'i hope you didnt translate it by hand.'
>>> b'map'.translate(t)
b'ocr'

No comments:

Post a Comment