[Python Challenge通关]第6关 now there are pairs

channel

挑战地址,点我

分析

右键查看网页源代码看一下:

<html> <!-- <-- zip -->
<head>
  <title>now there are pairs</title>
  <link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<center>
<img src="channel.jpg">
<br/>
<!-- 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
-->

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="thesamet@gmail.com">
    <input type="hidden" name="item_name" value="Python Challenge donations">
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="tax" value="0">
    <input type="hidden" name="bn" value="PP-DonationsBF">
    <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but04.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

</body>
</html>

中间一长段的注释是在说捐赠的事情,并且作者说明了与这一关的问题没有关系。

那唯一的提示,就是最上面的 <!-- <-- zip --> zip 常见的是压缩包的意思,其实还有拉链的意思,这就和图片对应起来了。

再看下这一关的主题now there are pairs,关键词 pairs 成对的,zip 左侧还有一个箭头指向 html

联想一下这些线索,猜想把 url 中的 html 替换为 zip http://www.pythonchallenge.com/pc/def/channel.zip

确实如此,我们下载 channel.zip 压缩包,解压看一下。

里面有 910 个数字命名的文本文件,其中有一个 readme.txt,打开看一下:

welcome to my zipped list.

hint1: start from 90052
hint2: answer is inside the zip

根据提示,去找下名字为 90052 的文件:

Next nothing is 94191

这和第 4 关类似,也是一个链表结构,用代码实现看下,这里用到了 zipfile 包来解压 zip 文件。

#!/usr/bin/env/ python3

import zipfile
import re

infile = "channel.zip 文件路径"

# 使用 zipfile 包解压并读取文件内容到 files
files = {}
with zipfile.ZipFile(infile) as fzip:
    for name in fzip.namelist():
        with fzip.open(name) as f:
            files[name] = f.read().decode("utf-8")

# readme.txt 中 nothing 初始值
nothing = "90052"

while True:
    f = nothing + ".txt"
    if f in files:
        print(files[f])
        result = re.search(r"Next nothing is (\d+)", files[f])
        try:
            nothing = result.group(1)
        except:
            break

输出结果:

Next nothing is 67824
Next nothing is 46145
Collect the comments.

提示信息 Collect the comments.,网页源码并没有什么有意义的 comments,也许 comments 也在压缩包里面?

查看下 zipfile 包的文档说明,有个 getinfo 方法,

调用该方法会返回一个 ZipInfo Objects,这个对象确实有个 comment 属性。

和上面的联系起来,在遍历整个链表的时候,获取每个文件的 comments 看下:

#!/usr/bin/env/ python3

import zipfile
import re

infile = "/home/roger/Documents/Resource/channel.zip"

# 使用 zipfile 包解压并读取文件内容到 files
files = {}
fzip = zipfile.ZipFile(infile)
for name in fzip.namelist():
    with fzip.open(name) as f:
        files[name] = f.read().decode("utf-8")

# readme.txt 中 nothing 初始值
nothing = "90052"

while True:
    f = nothing + ".txt"
    # 获取 comment 并输出结果
    print(fzip.getinfo(f).comment.decode("utf-8"), end="")
    if f in files:
        # print(files[f])
        result = re.search(r"Next nothing is (\d+)", files[f])
        try:
            nothing = result.group(1)
        except:
            break

输出内容:

****************************************************************
****************************************************************
**                                                            **
**   OO    OO    XX      YYYY    GG    GG  EEEEEE NN      NN  **
**   OO    OO  XXXXXX   YYYYYY   GG   GG   EEEEEE  NN    NN   **
**   OO    OO XXX  XXX YYY   YY  GG GG     EE       NN  NN    **
**   OOOOOOOO XX    XX YY        GGG       EEEEE     NNNN     **
**   OOOOOOOO XX    XX YY        GGG       EEEEE      NN      **
**   OO    OO XXX  XXX YYY   YY  GG GG     EE         NN      **
**   OO    OO  XXXXXX   YYYYYY   GG   GG   EEEEEE     NN      **
**   OO    OO    XX      YYYY    GG    GG  EEEEEE     NN      **
**                                                            **
****************************************************************
 **************************************************************

comment 中的字符组成了一个单词 hockey,用它来替换当前页面的 url 得到 http://www.pythonchallenge.com/pc/def/hockey.html

打开看到如下内容:

it's in the air. look at the letters.

翻译一下:它在空气中。 看看这些字母。,回头看下那些字符,hockey 是由 O X Y G E N 组成的,连起来就是 oxygen,这也是一个单词,氧气的意思,和提示内容符合。

oxygen 替换 url 得到下一关真正的入口了 http://www.pythonchallenge.com/pc/def/oxygen.html

参考资源:

  1. zipfile 官方文档
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值