pythonchallenge(0-4)

pythonchallenge 0:网址:http://www.pythonchallenge.com/pc/def/0.html

网页提示:try to change the URL addres。网站的图片提示如下:
在这里插入图片描述
图片的意思是网址为2的38次方

print(2**38)

得到下一关的网址:http://www.pythonchallenge.com/pc/def/274877906944.html

pythonchallenge 1:网址:http://www.pythonchallenge.com/pc/def/274877906944.html

网页跳转到:http://www.pythonchallenge.com/pc/def/map.html
在这里插入图片描述
给出的提示是:everybody thinks twice before solving this.通过图片发现K->M,O->Q,E->G,典型的凯撒密码加密,密钥就是2。根据一下提示:
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.
经过测试:g fmnc wms解密之后就是i hope you,构建一下paylaod:

text='''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.'''
lst=list(text)
lst2=[]
for i in lst:
    numb=ord(i)
    if numb>96 and numb<123:
        numb2=ord(i)+2
        if numb2>96 and numb2<123:
            lst2.append(chr(numb2))
        else:
            lst2.append(chr(numb2-122+96))      
    else:
        lst2.append(i)

print(''.join(lst2))

得到内容如下: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.我希望你不是亲手翻译的。这就是电脑的用途。用手写是低效的,这就是为什么这篇文章这么长。建议使用str.maketrans()方法。现在在网址上申请。
maketrans()方法:用于创建字符映射的转换表,对于接受两个参数的最简单的调用方式,第一个参数是字符串,表示需要转换的字符,第二个参数也是字符串表示转换的目标。两个字符串的长度必须相同,为一一对应的关系。
语法:str.maketrans(intab, outtab)
参数:intab – 字符串中要替代的字符组成的字符串。outtab – 相应的映射字符的字符串。
返回值:返回字符串转换后生成的新字符串。
根据提示内容,使用语法构建payload:

text='''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.'''
intabs="abcdefghijklmnopqrstuvwxyz"
outtabs="cdefghijklmnopqrstuvwxyzab"
trantab = text.maketrans(intabs, outtabs)
print (text.translate(trantab))

依旧得到刚才的内容,将text的内容换为‘map’:

text='map'
intabs="abcdefghijklmnopqrstuvwxyz"
outtabs="cdefghijklmnopqrstuvwxyzab"
trantab = text.maketrans(intabs, outtabs)
print (text.translate(trantab))

输出:ocr,得到下一关的网址:http://www.pythonchallenge.com/pc/def/ocr.html

pythonchallenge 3:网址: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.识别字符。它们可能在书中,也可能在页面源代码中。
在这里插入图片描述
查看源码,发现要找到稀有的文字,我们将以下内容保存在文本文档中(也可以在线获取)。根据题意需要统计文本内容中各个字符出现的次数,,使用most_common()函数,构建payload:

from collections import Counter
with open('e:/pythoncode/www.pythonchallenge.com/practice-02.txt','r') as f:
    text = f.read()
print(Counter(text).most_common())

得到:[(’)’, 6186), (’@’, 6157), (’(’, 6154), (’]’, 6152), (’#’, 6115), (’_’, 6112), (’[’, 6108), (’}’, 6105), (’%’, 6104), (’!’, 6080), (’+’, 6066), (’$’, 6046), (’{’, 6046), (’&’, 6043), (’*’, 6034), (’^’, 6030), (’\n’, 1221), (’-’, 4), (’<’, 1), (‘e’, 1), (‘q’, 1), (‘u’, 1), (‘a’, 1), (‘l’, 1), (‘i’, 1), (‘t’, 1), (‘y’, 1), (’>’, 1)]
稀有的字符:(’<’, 1), (‘e’, 1), (‘q’, 1), (‘u’, 1), (‘a’, 1), (‘l’, 1), (‘i’, 1), (‘t’, 1), (‘y’, 1), (’>’, 1)---->"<‘equality’>"
得到下一关的网址:http://www.pythonchallenge.com/pc/def/equality.html

pythonchallenge 4:网址:http://www.pythonchallenge.com/pc/def/equality.html

在这里插入图片描述
网页提示:One small letter, surrounded by EXACTLY three big bodyguards on each of its sides.一个小小的字母,两边各有三个魁梧的保镖。查看网页源码:
在这里插入图片描述
根据网页图片的提示url名称应该是三个大写一个小写再三个大写:AAAaAAA,大写的前后都不能再是大写,正则表达式提取:[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z],使用网页爬取的方式获取文本内容,构建payload:

import urllib.request
import  re
f=urllib.request.urlopen('http://www.pythonchallenge.com/pc/def/equality.html')
data=f.read()
data=data.decode('utf-8')
reg=re.compile('[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]')
print (''.join(reg.findall(data)))

输出:linkedlist,得到下一关的网址:http://www.pythonchallenge.com/pc/def/linkedlist.html

pythonchallenge 5:网址:http://www.pythonchallenge.com/pc/def/linkedlist.html

访问网址提示跳转:http://www.pythonchallenge.com/pc/def/linkedlist.php,查看源码发现网站中的图片有链接地址,且有提示:
在这里插入图片描述
urllib may help. DON’T TRY ALL NOTHINGS, since it will never end. 400 times is more than enough. 提示说urllib库可能会有所帮助。大概尝试400次就足够了。
点击图片,网页跳转到了,/linkedlist.php?nothing=12345,并且提示:and the next nothing is 44827,继续访问/linkedlist.php?nothing=44827,又提示and the next nothing is 45439。循环获取网页中的数字,添加到url中,构建payload:

import requests,re
numbers = re.compile("\d+")
numbs='12345'
def answer1():
    global numbs
    for i in range(401):
        #获取网页的文本
        source = requests.get("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="+numbs).text
        #提取网页中的数字
        numbs = re.findall(numbers,source)
        #判断是否含有数字,有的话继续测试,把内容打印出来没有打印出来
        if numbs:
            print(numbs[-1])
            numbs = numbs[-1]
        else:
            print(i,source)
            break
if __name__ == '__main__':
    answer1()

这里运行86次的时候提示:网页提示:Yes. Divide by two and keep going.,是的。除以2,继续。
在这里插入图片描述
改造answer1()函数,当提取到的网页中含有“Yes. Divide by two and keep going.”字符时将原来的数值/2,之后继续。

import requests,re
numbers = re.compile("\d+")
numbs='12345'
def answer2():
    global numbs
    for i in range(401):
        #获取网页的文本
        source = requests.get("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="+numbs).text
        #判断网页中是否含有“and the next nothing is ”,有的话就继续寻找,没有的话就判断
        if source.find("and the next nothing is") != -1:
            #提取网页中的数字
            numbs = re.findall(numbers,source)
            numbs = numbs[-1]
            print(numbs)
        else:
            #有没有“Divide by two and keep going.”,有的话将原来的数字/2,继续寻找,没有的话报错,提示网页内容。
            if source.find("Divide by two and keep going.") != -1:
                numbs = str(int(numbs)/2)
                print(numbs)
            else:
                print(i,source)
                break
if __name__ == '__main__':
    answer2()

输出:250 peak.html,得到下一关的网址:http://www.pythonchallenge.com/pc/def/peak.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码字的猴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值