Python Challenges

pythonchallenge

游戏入口 http://www.pythonchallenge.com/ 挺好玩的解密小游戏,会上瘾

第零关

Hint: try to change the URL address.

12**38 = 274877906944
1http://www.pythonchallenge.com/pc/def/274877906944.html

第一关

everybody thinks twice before solving this. 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.

看图:每个字符ASCII+2

1>>> for i in list(s):
2...     if ord(i)>=97 and ord(i)<=122:
3...             i = chr(ord(i)+2)
4...             if ord(i)>122:
5...                     i = chr(97+(ord(i)-122))
6...     ans += i
7...
8"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."

查了string.maketrans()用法后(人工也成)把url中的map -> orc 就行了

1>>>from string import maketrans
2>>>ori = "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."
3>>>aft = "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."
4>>> transtab = maketrans(ori,aft)
5>>> url.translate(transtab)
6'httr://yyy.rathopehcnngpig.eoo/re/fgh/ocr.hton'
7
8#so:url = http://www.pythonchallenge.com/pc/def/ocr.html

第二关

recognize the characters. maybe they are in the book, but MAYBE they are in the page source.

是要看页面的源码!?。。 源码中找到了:

 1<!--
 2find rare characters in the mess below:
 3-->
 4....
 5#很长,count()后发现有几个是字母。先复制给参数html
 6for i in html:
 7...     se.add(i)
 8...
 9
10>>> se
11set(['!', '#', '%', '$', '&', ')', '(', '+', '*', '@', '[', ']', '_', '^', 'a', 'e', 'i', 'l', 'q', 'u', 't', 'y', '{', '}'])
12>>> for i in list(se):
13...     print i,html.count(i)
14...
15! 6079
16# 6115
17% 6104
18$ 6046
19& 6043
20) 6186
21( 6154
22+ 6066
23* 6034
24@ 6157
25[ 6108
26] 6152
27_ 6112
28^ 6030
29a 1
30e 1
31i 1
32l 1
33q 1
34u 1
35t 1
36y 1
37{ 6046
38} 6105
39#字母都是1,这也验证了Hit
40其实知道是字母了直接re.findall('[a-z]',html)就成。题的真实用意?
41#so:http://www.pythonchallenge.com/pc/def/equality.html

第三关

One small letter, surrounded by EXACTLY three big bodyguards on each of its sides.

1>>> ans = abcdefghijklmnopqrstuvwxyz
2>>> import requests
3>>> for i in ans:
4...     r = requests.get('http://www.pythonchallenge.com/pc/def/{}.html'.format(i))
5...     print r.content
6...

到 l 时候:yes. but there are more. 试到y时候:It really looks like a Y, isn't it? now, go back. 好吧。。还是看页面源码去吧 : ) 开始以为是要处理字符串abc...z 和题2类似直接正则

1ans = re.findall('[a-z][A-Z]{3}([a-z])[A-Z]{3}[a-z]',html)
2>>> for i in ans:
3...     a+=i
4...
5>>> a
6'linkedlist'
7#so:http://www.pythonchallenge.com/pc/def/linkedlist.html
8#then 他有提示...
9#so:http://www.pythonchallenge.com/pc/def/linkedlist.php

第四关:只有图..

只能将源码中的这句话作为Hit:

urllib may help. DON’T TRY ALL NOTHINGS, since it will never end. 400 times is more than enough.

在一家大数据公司实习一个月了:所以看页面源码还是能看懂的✧(≖ ◡ ≖✿)嘿嘿 发现了href="linkedlist.php?nothing=12345" 和源码中的NOTHING正好对应那就访问呗。。他让用urllib,我习惯用requests..

 1url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing={}'
 2def get_data(i,u):
 3    r = requests.get(url.format(u))
 4    resp = r.content
 5    nothing = re.findall('\d+',resp)[0]
 6    print i,' nothing : ',nothing
 7    print resp
 8    return nothing
 9
10if __name__ == '__main__':
11    s = time.time()
12    nothing = '12345'
13    for i in xrange(400):
14        nothing = get_data(i+1,nothing)
15    print time.time() - s
16

跑到and the next nothing is 16044出了问题:Yes. Divide by two and keep going. 人工改下接着跑呗 :)… 好吧他真是怕你寂寞才设置这么多问题…

1#82683
2There maybe misleading numbers in the
3text. One example is 82683. Look only for the next nothing and the next nothing is 63579
4#改:nothing = re.findall('\d+',resp)[-1]
1#66831出了结果
2#so:http://www.pythonchallenge.com/pc/def/peak.html

第五关:

pronounce it source page: peak hell sounds familiar ?

英语一般很吃力啊,还发音?匹克好?皮卡哦? …去看文档https://docs.python.org/2/library/index.html peak搜无果pick搜搜倒有点意思了。。

1
2>>> a = pickle.dumps('peak')
3>>> print a
4S'peak'
5p0
6.

不对,又是忽略了什么。。

1<peakhell src="banner.p">
2<!-- peak hell sounds familiar ? -->
3</peakhell>
4#忽略了http://www.pythonchallenge.com/pc/def/banner.p
5#mmp,loads后还是不知所措 :)
6#似乎要排个序输出?不对,,每个小列表中的元组个数不一。。

随手写代码试试。。。

1>>> final = ''
2>>> for i in data:
3...     for ii in i:
4...             for iii in range(ii[1]):
5...                     final+=ii[0]
6...
7>>> final

十分有趣✧(≖ ◡ ≖✿)嘿嘿

1# so:http://www.pythonchallenge.com/pc/def/channel.html

第六关:

以后要把源码都分析好在往下分析。。

!– <– zip –> now there are pairs

!– The following has nothing to do with the riddle itself. I just thought it would be the right point to offer you to donate to the Python Challenge project. Any amount will be greatly appreciated. -thesamet –> ! - 以下与谜语本身无关。 我只是给你捐赠的正确点 —————————————————–mmp

信息不足。。看看cookie:

info: you+should+have+followed+busynothing… 没用,,只好想想zip和图片了 十分有趣✧(≖ ◡ ≖✿)嘿 http://www.pythonchallenge.com/pc/def/channel.zip

查了查要打开.zip用到 zipfile(人工点开也成。。)

 1class zipfile.ZipFile(file[, mode[, compression[, allowZip64]]])
 2ZipFile.namelist()
 3	获取zip文档内所有文件的名称列表
 4ZipFile.open(name[, mode[, pwd]])
 5#这些方法就够了
 6ZipFile.getinfo(name)
 7  获取zip文档内指定文件的信息返回一个zipfile.ZipInfo对象它包括文件的详细信息
 8ZipFile.infolist()
 9	获取zip文档内所有文件的信息返回一个zipfile.ZipInfo的列表
10ZipFile.printdir()
11	将zip文档内的信息打印到控制台上
12文档:
13#https://docs.python.org/2/library/zipfile.html#zipfile.ZipFile.getinfo
 1def process_num_6():
 2    with zipfile.ZipFile('channel.zip','r') as f:
 3        file_content = f.namelist()
 4        c = f.open('readme.txt','r')
 5        content =  c.readlines()[2][6:]
 6        print content
 7        while re.findall('(\d+)',content):
 8            num = re.findall('(\d+)',content)[0]
 9            content = '{}.txt'.format(num)
10            c = f.open(content,'r')
11            content =  c.readlines()[0]
12            print num,content
13#46145 Collect the comments.
14#改代码
15def process_num_6():
16    with zipfile.ZipFile('channel.zip','r') as f:
17        final = ''
18        file_content = f.namelist()
19        c = f.open('readme.txt','r')
20        content =  c.readlines()[2][6:]
21        print content
22        while re.findall('(\d+)',content):
23            num = re.findall('(\d+)',content)[0]
24            content = '{}.txt'.format(num)
25            ff = f.getinfo(content)
26            c = f.open(content,'r')
27            content =  c.readlines()[0]
28            print num,content,ff.comment
29            final+=ff.comment
30    print final
31#it's in the air. look at the letters.
32#十分有趣✧(≖ ◡ ≖✿)嘿嘿
1# so:http://www.pythonchallenge.com/pc/def/oxygen.html

第七关:

这次真的只有图片了。。。.png的图片

google了‘python怎么读写png图片中隐藏数据’ 出现了连接类似这样的‘python读取图片中B通道隐藏数据’ 所以解题方向应该就是这个了

 1#用的应该是The Image Module
 2#http://effbot.org/imagingbook/image.htm
 3def process_num_7():
 4    from PIL import Image
 5    im = Image.open('oxygen.png')
 6    pixdata=im.load()
 7    result=[]
 8    for y in xrange(43,52):#根据需要修改y范围
 9        for x in xrange(0,608):#根据需要修改x范围
10            data=pixdata[x,y][2]
11            result.append(chr(data))
12    print ''.join(result)
13#结果输出的好像有些问题但能看懂
14'''
15sssssmmmmmmmaaaaaaarrrrrrrttttttt       ggggggguuuuuuuyyyyyyy,,,,,,,       yyyyyyyooooooouuuuuuu       mmmmmmmaaaaaaadddddddeeeeeee       iiiiiiittttttt.......       ttttttthhhhhhheeeeeee       nnnnnnneeeeeeexxxxxxxttttttt       llllllleeeeeeevvvvvvveeeeeeelllllll       iiiiiiisssssss       ÆÆÆÆÆÆÆ111111100000005555555,,,,,,,       111111111111110000000,,,,,,,       111111111111116666666,,,,,,,       111111100000001111111,,,,,,,       111111100000003333333,,,,,,,       111111111111114444444,,,,,,,       111111100000005555555,,,,,,,       111111111111116666666,,,,,,,       111111122222221111111
16'''
17s = [105,110,116,101,103,114,105,116,121]
18>>> ans = ''
19>>> for i in s:
20...     ans+=chr(i)
21...
22>>> ans
23'integrity'

✧(≖ ◡ ≖✿)嘿嘿,图像处理挺有意思

1# so:http://www.pythonchallenge.com/pc/def/integrity.html

第八关:

Where is the missing link? 图中蜜蜂有鬼。。。有密码。。

1un: 'BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07<]\xc9\x14\xe1BA\x06\xbe\x084'
2pw: 'BZh91AY&SY\x94$|\x0e\x00\x00\x00\x81\x00\x03$ \x00!\x9ah3M\x13<]\xc9\x14\xe1BBP\x91\xf08'

编码问题?查了很多资料。。。

1#https://docs.python.org/2/library/bz2.html?highlight=bz2#module-bz2
2>>> import bz2
3>>> print(bz2.decompress(us).decode('utf-8'))
4huge
5>>> print(bz2.decompress(ps).decode('utf-8'))
6file
1# so:http://www.pythonchallenge.com/pc/return/good.html

第九关:connect the dots

好多图像处理,先学一波:

1http://pillow.readthedocs.io/en/3.4.x/reference/Image.html
2http://pythonguidecn.readthedocs.io/zh/latest/scenarios/imaging.html

连接点画图,first,second应该是坐标。。 用到的方法:

1#http://effbot.org/imagingbook/image.htm#tag-Image.new
2#http://pillow.readthedocs.io/en/3.4.x/reference/ImageDraw.html#imagedraw-module
 1def process_num_9():
 2    from PIL import Image,ImageDraw
 3    first = [146, 399, 163, , ]
 4    second = [156, 141, 165, , ]
 5    im = Image.new("RGB", (512, 512)) #开始把color设为'white',结果一片白。
 6    draw = ImageDraw.Draw(im)
 7    draw.line(zip(first[0::2], first[1::2]))
 8    draw.line(zip(second[0::2], second[1::2]))
 9    im.show()
10#运行结果是个牛的图像。。cow?
11#hmm. it's a male.。。。。。。公牛英语怎么说
1# so:http://www.pythonchallenge.com/pc/return/bull.html

第十关:what are you looking at?

先找clue href=“sequence.txt” len(a[30]) = ?

1#http://www.pythonchallenge.com/pc/return/sequence.txt
2a = [1, 11, 21, 1211, 111221,
3#后来发现,点图里的牛也成,和蜜蜂那关一样

看起来很简单?!

1把2拆了:
2a[1,11,111,11111,11111111,,]
3#其实就是各个位上的数求和
41,2,3,5,8,,似乎有规律,不过是错的。。
5想破头皮了~~
6知道什么是**外观数列**么
7https://zh.wikipedia.org/wiki/%E5%A4%96%E8%A7%80%E6%95%B8%E5%88%97
8先试试暴力。。。有反爬策略,,还是研究数列去吧
 1#根据wiki上外观数列的性质
 2def process_num_10():
 3    a=['11',]
 4    for i in range(30):
 5        node = ''
 6        now = a[i]
 7        num = 1
 8        for k in range(1,len(now)):
 9            if now[k-1]!=now[k]:
10                node += str(num)+ now[k-1]
11                num=1
12            else:
13                num+=1
14        node += str(num)+now[-1]
15        a.append(node)
16    print a
17    print len(a[29])
1# so:http://www.pythonchallenge.com/pc/return/5808.html

第十一关:odd even

这模糊的感觉,难道又是图像处理?

线索很少 odd even 奇偶 cave 洞穴

通过把奇数,偶数把坐标分成两份分别生成图像,结果一片黑,还是对图像处理不是特别理解。 多次尝试。。。 正确的如下:

 1def process_num_11():
 2    from PIL import Image, ImageDraw
 3    im = Image.open( 'cave.jpg' )
 4    im1 = Image.new("RGB", (640, 480))
 5    pixdata = im.load()
 6    for i in xrange(640):
 7        for j in xrange(480):
 8            if (i+j) %2== 0:
 9                im1.putpixel((i,j),pixdata[i,j])
10            else:
11                im1.putpixel((i,j),0)
12    im1.show()
1# so:http://www.pythonchallenge.com/pc/return/evil.html

第十二关:dealing evil

处理恶魔? 又是图像问题,满满的都是恶意 似乎这个游戏几乎图像问题。

hah…既然有evil1那么就有evil2,3,4…就2有用。

1#not jpg - gfx
2#http://www.pythonchallenge.com/pc/return/evil2.gfx
3#curl -u huge:file http://www.pythonchallenge.com/pc/return/evil4.jpg #或者直接去查看响应
4#response: Bert is evil! go back!

可是还是不会,,第一次听说.gfx文件

note:实习生活告一段落,开始玩游戏。

 1google: What is a GFX file?
 2
 3Animation file used by video games, such as Batman: Arkham Asylum and Mass Effect; similar to the .SWF file format; contains vector and raster graphics; also may include ActionScript interactive actions.
 4视频游戏使用的动画文件,如蝙蝠侠:阿卡姆庇护和质量效应; 类似于.SWF文件格式; 包含矢量和光栅图形; 也可能包含ActionScript交互式动作。
 5
 6google: how to open.gfx file in python
 7found-- http://www.swftools.org/gfx_tutorial.html
 8
 9似乎和gfx模块没多大关系。。
10
11---好难~~
 1直接打开文件试试吧
 2用sublime时候直接编译提示[Decode error - output not utf-8]
 3去shell看看
 4>>>doc2 = open("/Users/mioji/Desktop/evil2.gfx", "rb").read()
 5>>>doc2
 6输出一坨'\xff\x89G\x89\xff\xd8PIP\xd8\xffNFN\xff\xe0G8G\xe0\x00\r7\r\x00\x10\na\n\x10J\x1a@\x1aJF\n\x01\nFI\x00\xf0\x00IF\x00\x00\x00F\x00\x00\xe7\x00\x00\x01\r\x00\r\x01\x01I\x00I\x01\x01H\x00H\x01\x00D\x01D\x00\xb4R\x00R\xb4\x00\x00\x00\x00\x00\xb4\x00\x01\x00\xb4\x00\x01\x04\x01\x00\x00\x90\x02@\x00\xff\x00\x00\x00\xff\xe1\x00\x05\x00\xe1\x08\x01\x00\x00\x0b\xa4,\x02\xf0\xdfE\x08\x00\x08Ex\x02\x06\x02xi\x00\x00\x00if\x00\x00\x00f\x00\x00\x04\x00\x00\x00b\x00\xfe\x00M\xd5\x06OMMr\x00*M\x00\x95\x01<\x00*\x00\x0e\x00*\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x06\x06\t\x00\x08b\x01p\x08\x00K\x04H\x00\x00G\x00Y\x00\x00D\x00s\x00\x00\x00\x04\x00\x00\x00\x00\x07\x00\x00\x0e\x00\x05\x1b\x0e\x00\x00\x02\xaf\x00\x02\x00\x07.......'
 7>>> doc2.count('\n')
 8232
 9>>> len(doc2)
1067575
11---忍不住看了答案是要轮流分五份就像第一张图片分牌一样。(MD
12剩下就简单了。。回过头来看好像很简单。。。不过刚接触以为还要用到什么新模块呢无头苍蝇乱撞(╯▽╰)
13def process_num_12():
14    doc2 = open("/Users/mioji/Desktop/evil2.gfx", "rb").read()
15    for i in range(5):
16        with open('evil%s'%(str(i)),'wb') as f:
17            f.write(doc2[i::5])
1dis pro port ...我这边就显示上面一半 ity(被划掉了)算了去google翻译吧 Did you mean: disproportionate ,试了又试
2#so: disproportional
3http://www.pythonchallenge.com/pc/return/disproportional.html

第十三关:call him

phone that evil 看到这,瞬间想到12关的那个Bert is evil! go back! 不会这么容易吧。。。2378不对。。 难道国外电话要加#号?试了下加前面有用,#2378

1don't look here
2--至少不是404,后来发现。单独一个“#”返回也是这个信息。。。唉
 1剩下就这一个线索了,还打不开。。
 2http://www.pythonchallenge.com/pc/phonebook.php
 3还有一个就是源码中:
 4phone that <remote /> evil
 5remote call? WTF-_-
 6google:python remote call --还真有
 7pip install rpyc and help(rpyc) 学吧,,MD好像不是这个模块。。
 8
 9找了半天,不可避免的瞥到了答案:是用到xmlrpclib模块。看文档学习吧https://docs.python.org/2/library/xmlrpclib.html#xmlrpclib.ServerProxy
10知道模块了就简单了-----早点给个提示多好
 1>>>import xmlrpclib
 2>>>r = xmlrpclib.ServerProxy('http://www.pythonchallenge.com/pc/phonebook.php')
 3>>> type(r)
 4<type 'instance'>
 5>>> r.system.listMethods()
 6['phone', 'system.listMethods', 'system.methodHelp', 'system.methodSignature', 'system.multicall', 'system.getCapabilities']
 7>>> r.system.methodSignature('phone')
 8[['string', 'string']]
 9>>> r.system.methodHelp('phone')
10'Returns the phone of a person'
11>>> r.phone('bert')
12'He is not the evil'
13>>> r.phone('Bert')
14'555-ITALY'
15
16---这一步一步的跟着提示走根据文档就学了俩方法列出方法和Help原理还不是太明吧反正有答案了事实上他列出的方法我都试了我这里就展示有意义的线索
17
18http://www.pythonchallenge.com/pc/return/ITALY.html
19SMALL letters.
20#so:http://www.pythonchallenge.com/pc/return/italy.html

第十四关:walk around

 1应该是处理大便下面那个图片吧O__O 那是面包
 2http://www.pythonchallenge.com/pc/return/wire.png
 3源码中找到了提示remember: 100*100 = (100+99+99+98) + (...
 4而图片正好是100*100试试吧
 5
 6MD,单单这个公式推了半天最终试出来实验过程如下
 7>>> sum = 0
 8>>> num = 99
 9>>> for i in range(100):
10...     sum+= num*4
11...     num -= 2
12...     print sum
13会输出很多似乎到i= 49时候就等于10000了
14所以推测公式为100*100 = (100+99+99+98)+ (98+97+97+96)+(96+95+95+94)+...
 1下面才是正题--处理图像
 2>>> from PIL import Image, ImageDraw
 3>>> im = array(Image.open('/Users/mioji/Desktop/wire.png'))
 4>>> print len(im[0])
 510000
 6
 7#做实验时候还在纳闷:原来这个图像是10000*1的,所以图像下载下来是个长条。。。
 8#所以说公式没什么用- -WTF。
 9
10>>> for i in range(100):
11...     for j in range(100):
12...             im1[i][j]=im[0][num]
13...             num-=1
14...
15>>> imshow(im1)
16<matplotlib.image.AxesImage object at 0x109040250>
17>>> show()

展示的图像。bit?什么鬼。 这里写图片描述

1试了一下
2#http://www.pythonchallenge.com/pc/return/bit.html
3you took the wrong curve.
4可能那个公式还是有用的。。
5不不不,突然意识到那个大便有提示作用。。一圈一圈的。。
6O__O "…拙劣的代码写了个蛇形数组(而且还有Bug)。不提出来献丑了所有代码我都保存在github上,等通关了我放到最后,虽然那是一个漫长的时间。

这里写图片描述

不过能看清是只猫,其他都是细节✧(≖ ◡ ≖✿)嘿嘿

1# so:http://www.pythonchallenge.com/pc/return/cat.html

Contact Me
About
comments powered by Disqus