您的位置:首页 > 编程语言 > Python开发

python挑战之level 30

2016-10-03 23:29 281 查看
连接为:http://www.pythonchallenge.com/pc/ring/yankeedoodle.html

密码:(repeat,switch)

推荐视频: #30 relax you are on 30 一波三折

————————————————————————————————————————



标题:relax you are on 30

注释:
<!-- while you look at the csv file -->

提示:The picture is only meant to help you relax

——————————————————————————————————————————————————————————

那我们怎么样子解题呢?看注释,提示csv file ,我们改改后缀,结果有一个文件下载下来,这是一个excel.里面很多数据,包含7367个浮点数的文件不知道怎么计算。

百度一下:里面一共有7367个浮点数,7367=139*53,用浮点数*256当灰度画成139宽53高的图像。显示出了一个方程。

<pre name="code" class="python">import re
from  PIL import Image
with open('yankeedoodle.csv','r') as f:
text=f.read()
#获取浮点数列表
data=re.findall(r'([.\d+]+)',text)

#采用float*256获得灰度值
databyte=bytearray(int(256*float(i)) for i in data)
#写入图片中
im=Image.new('P',(53,139))
im.putdata(databyte)
#图片是倒置的。所以先旋转,然后在新图片上再颠倒
nim = im.transpose(Image.ROTATE_90)
nim = nim.transpose(Image.FLIP_TOP_BOTTOM)
nim.save('output.png')






使用方程:s = [chr(int(data[i][5]+data[i+1][5]+data[i+2][6])) for i in range(0,len(data)-2,3)]
print (''.join(s)) 结果为:

So, you found the hidden message.
There is lots of room here for a long message, but we only need very little space to say "look at grandpa", so the rest is just garbage. 

但是我的字符串后面多了一大串乱码。不知道怎么回事

下一关为:http://www.pythonchallenge.com/pc/ring/grandpa.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: