The Python Challenge

2024-04-09 20:36
文章标签 python challenge

本文主要是介绍The Python Challenge,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

The Python Challenge

地址:http://www.pythonchallenge.com/
一共33关
在这里插入图片描述

第0关

在这里插入图片描述很明显数字238,但是直接访问提示:No… the 38 is a little bit above the 2…
意思是38在2的上方,就是要2的38次方
运算print(2**38)得到结果

第1关

在这里插入图片描述

根据映射关系解密,我直接先去试了凯撒:
在这里插入图片描述在这里插入图片描述
将这个规则应用到URL上,就是将map进行+2的凯撒加密

使用Python代码:

intab = "KOE"
outtab = "MQG"
str = "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. "def convert(intstr, n):outstr = ""for i in intstr:if 'a' <= i <= 'z':id = ord(i) - ord('a') + noutstr += chr(ord('a')+ id%26)elif 'A' <= i <= 'Z':id = ord(i) - ord('A') + noutstr += chr(ord('A')+ id%26)else:outstr += ireturn outstrprint(convert(str,2))
url = "map"
print(convert(url,2))

第2关

在这里插入图片描述
查看网页源代码发现存在提示:find rare characters in the mess below
在这里插入图片描述

import requests
import re
def parse_ocr():url = "http://www.pythonchallenge.com/pc/def/ocr.html"response = requests.get(url)response_text = response.textdata = re.findall(r'<!--(.*?)-->',response_text, re.DOTALL)# print(data)for item in data:pattern = r'[a-zA-Z]'items = re.findall(pattern, item)print(''.join(items))
if __name__ == "__main__":parse_ocr()

第3关

在这里插入图片描述

import requests
import re
def parse_html():url = "http://www.pythonchallenge.com/pc/def/equality.html"response = requests.get(url)response_text = response.textdata = re.findall(r'<!--(.*?)-->',response_text, re.DOTALL)# print(data)for item in data:pattern = r'[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]'items = re.findall(pattern, item)print(''.join(items))
if __name__ == "__main__":parse_html()

第4关

在这里插入图片描述
在这里插入图片描述
查看页面源代码:
在这里插入图片描述
传入参数:
在这里插入图片描述
发现是对参数进行不断匹配,使用正则匹配参数

import requests
import redef get_url(number):url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing={}".format(number)response = requests.get(url)response_text = response.text# print(response_text)pattern = r"\d+"matches = re.findall(pattern,response_text)[0]print(matches)return get_url(matches)if __name__ == "__main__":number = "12345"number = "16044"    #Yes. Divide by two and keep going.number = "8022"number = "82683"    #You've been misleaded to here. Go to previous one and check.number = "82682"    #There maybe misleading numbers in the text. One example is 82683. Look only for the next nothing and the next nothing is 63579number = "63579"get_url(number)number = "66831"    #peak.html

参数为16044时匹配报错,查看页面,提示要除以2
在这里插入图片描述
参数为82683时匹配报错,查看页面,回到上一步参数
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述提示下一个参数应该是63579
运行到参数66831报错,查看页面
在这里插入图片描述

第5关

在这里插入图片描述
查看页面源代码
在这里插入图片描述
访问peakhell标签里面的资源banner.p
在这里插入图片描述需要对该文件进行解析:

import requests
import pickledef parse():url = "http://www.pythonchallenge.com/pc/def/banner.p"response = requests.get(url)items = pickle.loads(response.text.encode())for i in items:print(''.join([ j[0]*j[1] for j in i]))if __name__ == "__main__":parse()

运行结果:
在这里插入图片描述

第6关

在这里插入图片描述
查看页面源代码:
在这里插入图片描述根据zip提示下载源文件
在这里插入图片描述

查看90052.txt
在这里插入图片描述
对文件内容进行匹配,获取下一个文件名
运行到46145时报错
在这里插入图片描述
zipfile 的 comment 属性是用于获取或设置 ZIP 文件的注释信息。
对文件的注释进行收集:

import zipfile
import re
def get_next(name):with file_zip.open(name,'r') as f:content = f.read().decode()# print(content)# #正则匹配文件内容# number = re.findall('\d+',content)[0]# next_file = number + '.txt'# return get_next(next_file)#获取zipfile文件的comment属性item = file_zip.getinfo(name).commentcomment_list.append(item.decode())print(content)try:number = re.findall('\d+', content)[0]next_file = number + '.txt'except Exception:return Nonereturn get_next(next_file)if __name__ == "__main__":file_zip = zipfile.ZipFile(r"D:\...\下载\channel.zip")file_name = file_zip.namelist()comment_list = []get_next('90052.txt')print(''.join(comment_list))

在这里插入图片描述

第7关

在这里插入图片描述提示查看字母,前面运行结果里面的字母是:oxygen
在这里插入图片描述
。。。未完待续

这篇关于The Python Challenge的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/889151

相关文章

Python并行处理实战之如何使用ProcessPoolExecutor加速计算

《Python并行处理实战之如何使用ProcessPoolExecutor加速计算》Python提供了多种并行处理的方式,其中concurrent.futures模块的ProcessPoolExecu... 目录简介完整代码示例代码解释1. 导入必要的模块2. 定义处理函数3. 主函数4. 生成数字列表5.

Python中help()和dir()函数的使用

《Python中help()和dir()函数的使用》我们经常需要查看某个对象(如模块、类、函数等)的属性和方法,Python提供了两个内置函数help()和dir(),它们可以帮助我们快速了解代... 目录1. 引言2. help() 函数2.1 作用2.2 使用方法2.3 示例(1) 查看内置函数的帮助(

Python虚拟环境与Conda使用指南分享

《Python虚拟环境与Conda使用指南分享》:本文主要介绍Python虚拟环境与Conda使用指南,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、python 虚拟环境概述1.1 什么是虚拟环境1.2 为什么需要虚拟环境二、Python 内置的虚拟环境工具

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部

Python pip下载包及所有依赖到指定文件夹的步骤说明

《Pythonpip下载包及所有依赖到指定文件夹的步骤说明》为了方便开发和部署,我们常常需要将Python项目所依赖的第三方包导出到本地文件夹中,:本文主要介绍Pythonpip下载包及所有依... 目录步骤说明命令格式示例参数说明离线安装方法注意事项总结要使用pip下载包及其所有依赖到指定文件夹,请按照以

Python实现精准提取 PDF中的文本,表格与图片

《Python实现精准提取PDF中的文本,表格与图片》在实际的系统开发中,处理PDF文件不仅限于读取整页文本,还有提取文档中的表格数据,图片或特定区域的内容,下面我们来看看如何使用Python实... 目录安装 python 库提取 PDF 文本内容:获取整页文本与指定区域内容获取页面上的所有文本内容获取

基于Python实现一个Windows Tree命令工具

《基于Python实现一个WindowsTree命令工具》今天想要在Windows平台的CMD命令终端窗口中使用像Linux下的tree命令,打印一下目录结构层级树,然而还真有tree命令,但是发现... 目录引言实现代码使用说明可用选项示例用法功能特点添加到环境变量方法一:创建批处理文件并添加到PATH1

Python包管理工具核心指令uvx举例详细解析

《Python包管理工具核心指令uvx举例详细解析》:本文主要介绍Python包管理工具核心指令uvx的相关资料,uvx是uv工具链中用于临时运行Python命令行工具的高效执行器,依托Rust实... 目录一、uvx 的定位与核心功能二、uvx 的典型应用场景三、uvx 与传统工具对比四、uvx 的技术实

Python中使用uv创建环境及原理举例详解

《Python中使用uv创建环境及原理举例详解》uv是Astral团队开发的高性能Python工具,整合包管理、虚拟环境、Python版本控制等功能,:本文主要介绍Python中使用uv创建环境及... 目录一、uv工具简介核心特点:二、安装uv1. 通过pip安装2. 通过脚本安装验证安装:配置镜像源(可

python判断文件是否存在常用的几种方式

《python判断文件是否存在常用的几种方式》在Python中我们在读写文件之前,首先要做的事情就是判断文件是否存在,否则很容易发生错误的情况,:本文主要介绍python判断文件是否存在常用的几种... 目录1. 使用 os.path.exists()2. 使用 os.path.isfile()3. 使用