the python challenge闯关记录(9-16)

9 第九关

 是一张图,上面有很多的黑点,查看网页源代码发现了上一关的提示:

还发现了一大串的数字

感觉又是一个使用PIL库进行图像处理的题,百度后知道要将这些点连接起来并重新画图。但是不能在原始图上修改,我们应该重新画图并进行修改。

编写代码:

from PIL import Image

def main(three):
    img = Image.open('good.jpg')
    # 利用img的模式和大小创建新图片
    img1 = Image.new(img.mode, img.size)
    # 两两为一个像素位置
    positions = []
    for i in range(0, len(three), 2):
        position = (three[i], three[i+1])
        positions.append(position)
    for j in positions:
        img1.putpixel(j, (255, 255, 255))
    img1.show()
    
if __name__ == '__main__':
    first = [146,399,163,403,170,393,169,391,166,386,170,381,170,371,170,355,169,346,167,335,170,329,170,320,170,
310,171,301,173,290,178,289,182,287,188,286,190,286,192,291,194,296,195,305,194,307,191,312,190,316,
190,321,192,331,193,338,196,341,197,346,199,352,198,360,197,366,197,373,196,380,197,383,196,387,192,
389,191,392,190,396,189,400,194,401,201,402,208,403,213,402,216,401,219,397,219,393,216,390,215,385,
215,379,213,373,213,365,212,360,210,353,210,347,212,338,213,329,214,319,215,311,215,306,216,296,218,
290,221,283,225,282,233,284,238,287,243,290,250,291,255,294,261,293,265,291,271,291,273,289,278,287,
279,285,281,280,284,278,284,276,287,277,289,283,291,286,294,291,296,295,299,300,301,304,304,320,305,
327,306,332,307,341,306,349,303,354,301,364,301,371,297,375,292,384,291,386,302,393,324,391,333,387,
328,375,329,367,329,353,330,341,331,328,336,319,338,310,341,304,341,285,341,278,343,269,344,262,346,
259,346,251,349,259,349,264,349,273,349,280,349,288,349,295,349,298,354,293,356,286,354,279,352,268,
352,257,351,249,350,234,351,211,352,197,354,185,353,171,351,154,348,147,342,137,339,132,330,122,327,
120,314,116,304,117,293,118,284,118,281,122,275,128,265,129,257,131,244,133,239,134,228,136,221,137,
214,138,209,135,201,132,192,130,184,131,175,129,170,131,159,134,157,134,160,130,170,125,176,114,176,
102,173,103,172,108,171,111,163,115,156,116,149,117,142,116,136,115,129,115,124,115,120,115,115,117,
113,120,109,122,102,122,100,121,95,121,89,115,87,110,82,109,84,118,89,123,93,129,100,130,108,132,110,
133,110,136,107,138,105,140,95,138,86,141,79,149,77,155,81,162,90,165,97,167,99,171,109,171,107,161,
111,156,113,170,115,185,118,208,117,223,121,239,128,251,133,259,136,266,139,276,143,290,148,310,151,
332,155,348,156,353,153,366,149,379,147,394,146,399]
    second = [156,141,165,135,169,131,176,130,187,134,191,140,191,146,186,150,179,155,175,157,168,157,163,157,159,
157,158,164,159,175,159,181,157,191,154,197,153,205,153,210,152,212,147,215,146,218,143,220,132,220,
125,217,119,209,116,196,115,185,114,172,114,167,112,161,109,165,107,170,99,171,97,167,89,164,81,162,
77,155,81,148,87,140,96,138,105,141,110,136,111,126,113,129,118,117,128,114,137,115,146,114,155,115,
158,121,157,128,156,134,157,136,156,136]
    main(first+second)

得到图像:

图像上是个牛,就是英文的bull

那么第十关的url为:http://www.pythonchallenge.com/pc/return/bull.html

10 第十关

看标题好像是求len(a[30])是多少,查看网页源代码

发现一大串数据,并且发现一个txt文件

点开后发现是一个列表

百度后才知道含义

11— 表示前一个数“1”是 1 个 1;
21— 表示前一个数“11”是 由 2 个 1 组成;
1211— 表示前一个数“21”是 由 1 个 2、1 个 1 组成;
111221— 即 11 12 21 ,表示前一个数“1211”是依次由 1 个 1,1 个 2,
2 个 1组成;

那么后一组的数据就会是312211

于是编写程序求解低30位是什么元素:

def main():
    # 申请2个字符串,一个为1,一个为空,a是用来存放数据的
    a = '1'
    sub1 = ''
    for i in range(30):
        j = k = 0
        while j <len(a):
            while k < len(a) and a[k] == a[j]:
                k += 1
            sub1 += str(k-j) + a[j]
            j = k
        a = sub1
        sub1 = ''
    print(len(a))

if __name__ == '__main__':
    main()

得到答案:

所以低11关的url是:http://www.pythonchallenge.com/pc/return/5808.html

 11 第十一关

查看网页源代码

标题叫做奇偶,应该和图像处理有关,修改制定位置的像素,我们把图片下载到本地,修改奇数位置的像素:

from PIL import Image

im = Image.open('cave.jpg')
odd = Image.new(im.mode, (im.size[0], im.size[1]))
for x in range(1, im.size[0], 2):
    for y in range(1, im.size[1], 2):
        odd.putpixel(((x-1),(y-1)),im.getpixel((x, y)))
odd.show()

得到结果:

有个单词evil,试了下

则12关的url是:http://www.pythonchallenge.com/pc/return/evil.html

如果要求输入账号密码,还是输入 huge file

12 第十二关

这题的源代码也没有任何提示,估计又是和图像梳理有关

发现图形的url为:http://www.pythonchallenge.com/pc/return/evil1.jpg

试着把evil1改为evil2,出现

图上说not jpg 而是 gfx,于是后缀修改为gfx,自动就把gfx文件下载下来了

将evil2修改为evil3出现

看来关键点就在下载下的evil.gfx文件

evil1图上是把扑克分成了5份,于是我们把evil.gfx文件也分成5份,evil.gfx的第一个字节给第一个文件,第二个字节给第二个文件,第三个字节给第三个文件,第四个字节给第四个文件,第五个字节给第五个文件,第六个字节给第一个文件,第七个字节给第二个文件……

编写代码:

with open('evil2.gfx', 'rb') as f:
    data = f.read()
for i in range(5):
    with open('evil%d.jpg'%i, 'wb') as f1:
        f1.write(data[i::5])

得到五张图:

连起来的单词是:disproportional

所以第13关的url是:http://www.pythonchallenge.com/pc/return/disproportional.html

13 第十三关

查看网页源代码

点击php文件,发现提示信息

百度得到提示 是使用xmlrpclib,即xml的远程方法调用(https://www.jb51.net/article/44515.htm

import xmlrpc.client

s = xmlrpc.client.ServerProxy('http://www.pythonchallenge.com/pc/phonebook.php')
print(s.system.listMethods())

得到输出:

看到有个phone方法,于是修改代码:

由上题的提示得知,这个恶魔的名字叫Bert,必须在ie浏览器打开

import xmlrpc.client

s = xmlrpc.client.ServerProxy('http://www.pythonchallenge.com/pc/phonebook.php')
print(s.system.methodHelp('phone'))
print(s.phone('Bert'))

得到答案:

第14关的url是:http://www.pythonchallenge.com/pc/return/italy.html

14 第十四关

 

打开网页源代码

发现提示提多的:

  1 walk around

  2 remember: 100*100 = (100+99+99+98) + (...

  3 有个图片wire.png

from PIL import Image

im = Image.open('wire.png')
print(im.size)

则它的像素为:(10000, 1)

那么这道题要做的是将10000*1的图像改成100*100的图像,像绕圈圈一样,先向右走100步,然后再向下走99步,再向左走99步,再向上走98步。典型的蛇形矩阵

from PIL import Image

im = Image.open('wire.png')
im1 = Image.new(im.mode, (100, 100))
# 代表四个方向 right down left up
direction = [(1, 0), (0, 1), (-1, 0), (0, -1)]
# 初始位置
x , y = -1 ,0
k = 0
# 100*100 = [[100, 99, 99, 98],[98, 97, 97, 96]]...应该有200个元素,
steps = 200
while steps/2>0:
    # 做一圈的迭代
    for vector in direction:
        step = steps//2
        for i in range(step):
            x = x + vector[0]
            y = y + vector[1]
            pixel = im.getpixel((k, 0))
            im1.putpixel((x, y), pixel)
            k += 1
        steps -= 1
im1.show()

得到一个图像:

是个猫。对应的英文应该是cat.

第14关的url为:http://www.pythonchallenge.com/pc/return/cat.html

输入发现是张图,有提示:

所以第14关的url应该为:http://www.pythonchallenge.com/pc/return/uzi.html

15 第十五关

 

有一张日历图,仔细看26号这天是被圈出来的

查看网页源代码

 收到了2个提示:

  1 他不是最年轻的吗,他是第二位的

  2 要做的事,为了明天买花

再看日历右下角,二月有29号,所以这一年是闰年。需要我们求出闰年时,1月27号是星期二的日期。

于是编写代码:

import datetime
import calendar

for year in range(1800, 2000):
    t = datetime.date(year,1,27)
    if calendar.isleap(year) and t.weekday() == 1:
        print(t)

得到结果:

百度出1756-1-27莫扎特出生

所以答案是:mozart

第十六关的url是:http://www.pythonchallenge.com/pc/return/mozart.html

16 第十六关

查看网页源代码:

上面的语句意思是让我们做吧,是句俚语

打印每行像素的值,我们发现每行像素都有连续5个195的值

我们以195为基准位置,反转一下色素,得到新的图片

编写程序:

from PIL import Image

im = Image.open('mozart.gif')
widt, heig = im.size
for y in range(heig):
    line = [im.getpixel((x,y)) for x in range(widt)]
    idx = line.index(195)
    lines = line[idx:] + line[:idx]
    for x in range(widt):
        im.putpixel((x, y), lines[x])
im.show()

 得到图片:

 

第17关的url为:http://www.pythonchallenge.com/pc/return/romance.html

 

posted @ 2019-04-14 23:33  噼里巴啦  阅读(238)  评论(0编辑  收藏  举报