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进行JSON和Excel文件转换处理指南

《Python进行JSON和Excel文件转换处理指南》在数据交换与系统集成中,JSON与Excel是两种极为常见的数据格式,本文将介绍如何使用Python实现将JSON转换为格式化的Excel文件,... 目录将 jsON 导入为格式化 Excel将 Excel 导出为结构化 JSON处理嵌套 JSON:

Python操作PDF文档的主流库使用指南

《Python操作PDF文档的主流库使用指南》PDF因其跨平台、格式固定的特性成为文档交换的标准,然而,由于其复杂的内部结构,程序化操作PDF一直是个挑战,本文主要为大家整理了Python操作PD... 目录一、 基础操作1.PyPDF2 (及其继任者 pypdf)2.PyMuPDF / fitz3.Fre

python设置环境变量路径实现过程

《python设置环境变量路径实现过程》本文介绍设置Python路径的多种方法:临时设置(Windows用`set`,Linux/macOS用`export`)、永久设置(系统属性或shell配置文件... 目录设置python路径的方法临时设置环境变量(适用于当前会话)永久设置环境变量(Windows系统

python中列表应用和扩展性实用详解

《python中列表应用和扩展性实用详解》文章介绍了Python列表的核心特性:有序数据集合,用[]定义,元素类型可不同,支持迭代、循环、切片,可执行增删改查、排序、推导式及嵌套操作,是常用的数据处理... 目录1、列表定义2、格式3、列表是可迭代对象4、列表的常见操作总结1、列表定义是处理一组有序项目的

python运用requests模拟浏览器发送请求过程

《python运用requests模拟浏览器发送请求过程》模拟浏览器请求可选用requests处理静态内容,selenium应对动态页面,playwright支持高级自动化,设置代理和超时参数,根据需... 目录使用requests库模拟浏览器请求使用selenium自动化浏览器操作使用playwright

python使用try函数详解

《python使用try函数详解》Pythontry语句用于异常处理,支持捕获特定/多种异常、else/final子句确保资源释放,结合with语句自动清理,可自定义异常及嵌套结构,灵活应对错误场景... 目录try 函数的基本语法捕获特定异常捕获多个异常使用 else 子句使用 finally 子句捕获所

Python极速搭建局域网文件共享服务器完整指南

《Python极速搭建局域网文件共享服务器完整指南》在办公室或家庭局域网中快速共享文件时,许多人会选择第三方工具或云存储服务,但这些方案往往存在隐私泄露风险或需要复杂配置,下面我们就来看看如何使用Py... 目录一、android基础版:HTTP文件共享的魔法命令1. 一行代码启动HTTP服务器2. 关键参

Python对接支付宝支付之使用AliPay实现的详细操作指南

《Python对接支付宝支付之使用AliPay实现的详细操作指南》支付宝没有提供PythonSDK,但是强大的github就有提供python-alipay-sdk,封装里很多复杂操作,使用这个我们就... 目录一、引言二、准备工作2.1 支付宝开放平台入驻与应用创建2.2 密钥生成与配置2.3 安装ali

Python获取浏览器Cookies的四种方式小结

《Python获取浏览器Cookies的四种方式小结》在进行Web应用程序测试和开发时,获取浏览器Cookies是一项重要任务,本文我们介绍四种用Python获取浏览器Cookies的方式,具有一定的... 目录什么是 Cookie?1.使用Selenium库获取浏览器Cookies2.使用浏览器开发者工具

Python实现批量提取BLF文件时间戳

《Python实现批量提取BLF文件时间戳》BLF(BinaryLoggingFormat)作为Vector公司推出的CAN总线数据记录格式,被广泛用于存储车辆通信数据,本文将使用Python轻松提取... 目录一、为什么需要批量处理 BLF 文件二、核心代码解析:从文件遍历到数据导出1. 环境准备与依赖库