Python Challenge系列解题14-18

#注意啊,访问网页需要用到的用户名和密码是在之前一道题目中破解的,用户名是:huge ;密码:file

Python Challenge 14

walk around
Python Challenge 14
打开网站,照例是如图所示的图片,发现下面小的缩略图提示:
![Hint](https://img-blog.csdnimg.cn/20190220222451262.png
然后看看源网页,发现如图提示如下:

<!-- remember: 100*100 = (100+99+99+98) + (...  -->

<img src="wire.png" width="100" height="100">

仔细观察,发现这个线索图案正好是100100的大小,而100100被诠释为(100+99+99+98)···这个东西是不是有点像小学奥数里面的填图案,从第一行开始从左往右填写,到头之后再往下,再往左,再向上;重复这个过程直到图案被填满。

Solution 14

所以,我们用之前的方法把图像中点的信息获取到,然后按上述方法将其画进一个新图里,代码如下:

from PIL import Image
img_load = Image.open("wire_png_filepath")
img = Image.new("RGB",(100,100))
x,y,z = -1,0,0  # 定义初始值
towards = [(1,0),(0,1),(-1,0),(0,-1)]
flag = 200  #设为200可以每次在循环中让flag—1,整数除法除以2得到正确的结果
while flag/2 > 0 :
	for k in towards: 
		go = flag//2
		for j in range(go):
			x,y = x+towards[0],y+toward[1]
			img.putpixel = ((x,y),img_load.getpixel((z,0))
			z++
		flag--		#通过flag控制go决定像素点转换方向的位置

bingo,得到结果,ねこちゃん~
在这里插入图片描述
输入flag,得到这个东西

uzi
Challenge 15
em,告诉你小猫咪的名字叫uzi:‘ and its name is uzi. you’ll hear from him later.’好吧,直接输入uzi进入下一题,小猫咪的名字就是flag

Python Challenge 15

Solution 15

whom?
Challenge 15
页面中是一张日历,上面圈出了26,再看看源网页提示:

<!-- he ain't the youngest, he is the second -->
<!-- todo: buy flowers for tomorrow -->

大概观察一下日历,发现年份中间的数字是模糊的,加上日历右下角的日历是2月份,闰年(好吧我看攻略的,这个分辨率是真的看不清楚),所以简言之,找到1xx6年间1月26号是周一的闰年,写代码吧:

import datatime #python的一个时间日期显示库,可以仔细看看
for i in range(1016,1996,20):	#因为第一个1xx6闰年为1016,并且每增加20 = 4*5年才会有第二个结尾为6的闰年到来
	if datetime.dat(i,1,26).isoweekday() == 1:	#函数方法,判断是否为周一
		print (i+2006) #打印符合条件的函数

得到结果如下:

1176
1356
1576
1756
1976

因为线索里说给第二天准备花,并且这个人是第二年轻的,应该是1756-1-27,所以百度一下和什么人有关,发现时Mozart的生日···
所以输入flag进入下一题吧··

Python Challenge 16

let me get this straight
Challenge 16
题目给了一张看起来噪点很多的图,再看看源网页,只有题目的一句提示,注意观察图中的噪点,有粉色的条条看起来是我们需要的点,不妨用PIL库先筛选处理一下:

from PIL import Image
img = Image.open("filename")
img.show()

仔细观察图片,发现图中似乎有许多小的粉色点点,有兴趣的话,枚举计数看一看图中都有什么类型的点:

flag = 0
while flag < len(img.instogram())print ('<%d,%d>'%(i,img.instogram()[i-1]),end = '')
##  img.histogram()函数会以索引、个数的格式返回图片中不同色像素点的统计个数

想利用这个计数统计找到我们需要的色块,就去再仔细观察一下,发现其实每行都有一个相同颜色几乎一样长的小条,那么会不会这个小条就是线索?小条如果一样大的话,那小条的计数应该也是能被图片像素列数整除的吧?试试看:

>>>[i for i in img.histogram() if i % img.height == 0 and i != 0 ]
[2400]
>>>img.histogram().index(2400)
[195]

果然,找到了唯一的元素,序号是195,打开看看:
用nmpy读取图片矩阵进行行列操作,如下:

import numpy as np
>>> shifted_pic = [bytes(np.roll(row, -row.tolist().index(195)).tolist()) for row in np.array(img)] #将图片矩阵按行读取,找到色块开始的索引并且将其移动到最左端

img_new = Image.frombytes(image.mode, image.size, b"".join(shifted_pic))

首先我们用np.array(img)函数读取图片信息(做机器学习、深度学习),然后用row.tolist().index(195)获取改色块信息,接着用np.roll()帮助我们将其移动到最左端(减去其索引),转换之后用image.frombyte()创建新的图片,显示得到结果:

img_new.show()

在这里插入图片描述
bingo,输入romance进入下一题

Python Challenge 17

eat?
Challenge 17
然后查看源代码也没有发现有什么有用的东西,只有cookies.jpg这个文件,这个cookies的谐音让人不得不联想到cookie信息,首先尝试输入cookies.html,发现了提示yummy,chocolate chips,然后注意左下角的图片似曾相识,发现时第四题的图片,em,再试试cookies.php? 遗憾的发现不是。

Solution 17

首先看看网页的cookie信息(点击网页地址栏前面的小感叹号就能看到),发现cookie里面包含了信息内容you+should+have+followed+busynothing...再加上之前第四题的信息,仔细想想,应该是发现第四题里面的链接头在nothing前面加上busy,http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=进入第一个页面,发现果然cookie里面有信息,是个字符Z,考虑到之前的情况,逐步爬取cookie信息即可:

import urllib.request
import urllib.parse
import re,bz2
add_temp = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="
add_s = '12345'
pattern = re.compile("the next busynothing is (\d+)")
while add_s:
	html_raw = urllib.request.urlopen(add_temp+add_s)
	html=html_raw.read().decode()
	print(html)
	match = pattern.search(html)  
	cookie = html_raw.getheader("Set-Cookie")
	info += re.search('info = (.*?);',cookie).group(1)
	if match == None:
		break;
	else:
		add_s = match.group(1) 

用这种方法最终可以得到保存在cookie中的信息:

'BZh91AY%26SY%94%3A%E2I%00%00%21%19%80P%81%11%00%AFg%9E%A0+%00hE%3DM%B5%23%D0%D4%D1%E2%8D%06%A9%FA%26S%D4%D3%21%A1%EAi7h%9B%9A%2B%BF%60%22%C5WX%E1%ADL%80%E8V%3C%C6%A8%DBH%2632%18%A8x%01%08%21%8DS%0B%C8%AF%96KO%CA2%B0%F1%BD%1Du%A0%86%05%92s%B0%92%C4Bc%F1w%24S%85%09%09C%AE%24%90'

很容易发现这个和之前一道题的格式非常相似,那个用bz2模块解压缩的形式,使用urllib.parse模块里的unquote_to_bytes()模块可以得到bz2能够解码的形式:

res = urllib.parse.unquote_to_bytes(info.replace("+"," "))
print(res)
print(bz2.decompress(res).decode())

得到最终结果:

is it the 26th already? call his father and inform him that "the flowers are on their way". he'll understand.

em,26th还是莫扎特那道题,网上查了一下攻略,发现是他爸的名字…Leopold,所以用之前一道题的远程方法调用,给他爸打电话,代码如下:

from xlrpc.client import ServerProxy
conn = ServerProxy("http://www.pythonchallenge.com/pc/phonebook.php")
print(conn.phone("Leopold"))

得到结果555-VIOLIN,所以我们试试输入flag是violin,依照引导让网页来到位置,发现没什么有用的信息量,源码里有一句Its me ,what do you want?`,结合之前的信息,考虑到应该吧那句话加到cookie里面看看是什么结果:

from urllib.request import Request, urlopen
from urllib.parse import quote_plus

url = "http://www.pythonchallenge.com/pc/stuff/violin.php"
msg = "the flowers are on their way"
req = Request(url, headers = { "Cookie": "info=" + quote_plus(msg)})

print(urlopen(req).read().decode())

发现返回的网页里面有,oh,don`t you dare forget the balloons.输入balloons进入下一题

Python Challenge 18

Can you tell the difference?
Challenge 18
源网页里面有这么一句提示:

<!-- it is more obvious that what you might think -->

Solution 18

这个应该和图片的亮暗度有关,我们输入brightness,得到下一条源码提示:

<!-- maybe consider deltas.gz -->

导入gzip文件,打开文件,发现数据大概分成了两块,所以导入相应的库对文件进行处理:

import gzip,difflib

data = gzip.open("deltas.gz")
d1,d2 = [],[]
for line in data:
	d1.append(line[:53].decode()+"\n")
	d2.append(line[56:].decode())

compare = difflib.Differ().compare(d1,d2)  #此函数会将两个文件块互相比较,"+"开头的行是d1中有d2中没有的,"-"是d2中有d1中没有的内容,

f = open("f.png","wb")
f1 = open("f1.png","wb")
f2 = open("f2.png","wb")

for line in compare:
	bs = bytes([int(o,16) for o in line[2:].strip().split(" ") if o])
	 if line[0] == '+':
        f1.write(bs)
    elif line[0] == '-':
        f2.write(bs)
    else:
        f.write(bs)

最终得到三张图片中的内容为:

f: .../hex/bin.html
f1: butter
f2: fly

所以,改变路径,在弹出的对话框中输入用户名和密码,然后按顺序输入butter和fly,进入下一道题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值