Python Challenge 第一关
偶然在网上看到这个,PYTHON CHALLENGE,利用Python语言闯关,觉得挺有意思,就记录一下。
第0关应该算个入口吧,试了好几次才试出来,没什么代码就不写了。计算一个结果出来就行。
第一关,给了一个图和一段文字。那段文字明显是经过加密的:
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.
然后图上有三行提示:"K->M O->Q E->G"。我开始想法很简单,将这段字符串中的这三个字母替换一下。。结果出来还是看不懂,就知道自己想法太简单了。
再仔细看了看图中的三行提示,发现替换后的字母都是替换前字母的后2位,于是想试一试将所有的字母往后移两位。首先的想法就是处理ASCII码:
def changeStr0(srcStr):
dstStr = ''
for i in srcStr:
if i.islower():
dstStr += chr((ord(i) - ord('a') + 2) % 26 + ord('a'))
else:
dstStr += i
return dstStr
判断源字符串中的每一项,若是小写字母,将它的ASCII码后移两位再转换回字母,为了避免后面几位加了2得到其他符号,这里使用ASCII码的差模26。
将这个字符串解码后得到下面的句子:
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.
这时候才知道还有string.maketrans()这个函数。于是在解释器里输入 help(string.maketrans) 得到:
maketrans(...)
maketrans(frm, to) -> string
Return a translation table (a string of 256 bytes long)
suitable for use in string.translate. The strings frm and to
must be of the same length.
这个函数会根据frm和to这两个字符串返回一个table,两个参数长度要一样,把frm中对应的字母换成to中对应的字母。返回值table用来给string.translate函数做参数。又去查了下string.tanslate():
translate(s, table, deletions='')
translate(s,table [,deletions]) -> string
Return a copy of the string s, where all characters occurring
in the optional argument deletions are removed, and the
remaining characters have been mapped through the given
translation table, which must be a string of length 256. The
deletions argument is not allowed for Unicode strings.
这个函数根据table将s中的字母替换,并删掉可选参数deletions中字符。于是有了第二版:
def changeStr1(srcStr):
frm = string.letters[0:26]
to = string.letters.lower()[2:28]
table = string.maketrans(frm, to)
return srcStr.translate(table)
这个版本就简单多了。然后利用写好的函数,将url中的map处理一下得到ocr,就可以进入下一关了:http://www.pythonchallenge.com/pc/def/ocr.html
Python Challenge 第一关的更多相关文章
- The Python Challenge 闯关笔记
The Python Challenge : http://www.pythonchallenge.com/ Level 0: 看提示图片中为2**38,计算值为274877906944. Hint: ...
- the python challenge闯关记录(0-8)
0 第零关 2**38 = 274877906944 下一关的url:http://www.pythonchallenge.com/pc/def/274877906944.html 1 第一关 移位计 ...
- Python Challenge 第二关
第二关和第一关一样,还是一幅图和一行提示.提示说的是: recognize the characters. maybe they are in the book, but MAYBE they are ...
- the python challenge闯关记录(9-16)
9 第九关 是一张图,上面有很多的黑点,查看网页源代码发现了上一关的提示: 还发现了一大串的数字 感觉又是一个使用PIL库进行图像处理的题,百度后知道要将这些点连接起来并重新画图.但是不能在原始图上修 ...
- Python Challenge 第九关
第九关只有一幅图,上面有一些黑点.网页名字叫:connect the dots.可能是要把这些点连起来. 查看源代码,果然有两个整数集合 first 和 second.并且有个提示:first+sec ...
- python challenge第1关--NoteBook上的“乱码”
在 python challenge第0关中已经得到第1关的地址了: http://www.pythonchallenge.com/pc/def/map.html 一.观察地址栏和标签: What a ...
- Python 爬虫闯关(第一关)
在学习爬虫时,遇到了一个有意思的网站,这个网站设置了几个关卡,需要经过爬虫进行闯关,随着关卡的网后,难度不断增加,在闯关的过程中需要学习不同的知识,你的爬虫水平也自然随之提高. 今天我们先来第一关,访 ...
- Python:黑板课爬虫闯关第一关
近日发现了[黑板课爬虫闯关]这个神奇的网页,练手爬虫非常的合适 地址:http://www.heibanke.com/lesson/crawler_ex00/ 第一关非常的简单 get 请求网址,在响 ...
- The Python Challenge 0-4
The Python Challenge 0-4 项目地址:http://www.pythonchallenge.com/ Level-0 提示Hint: try to change the URL ...
随机推荐
- 【SAM】loj#6401. 字符串
网上有篇题解写的是线段树合并维护求值? 题目描述 有一个只包含小写字母,长度为 $n$ 的字符串 $S$ .有一些字母是好的,剩下的是坏的. 定义一个子串 $S_{l\ldots r}$是好的,当且仅 ...
- R,RJAVA 安装配置 详细版
准备工作 系统必须已经安装JDK 并配置好了环境变量. 注:安装的jdk r 以及系统 尽量保持位数一致 1.下载 R https://mirrors.tuna.tsinghua.edu.cn ...
- 素材网站——mokuge
- Optimization & Map
- JS处理数据四舍五入,tofixed与round的区别
此区别是在做微信端有关绑定设备数据曲线平滑处理的过程中,进行验证时候无意发现. 1 .tofixed方法 toFixed() 方法可把 Number 四舍五入为指定小数位数的数字.例如将数据Num保留 ...
- PHP分页类代码
今天为大家献上一段代码,这是一段php分页代码: <?php//创建分页类class Page { private $_all_num; ...
- Python 基本数据类型 (二) - 字符串1
# ----------- 首字母大写 ---------- test = "alex is a man" v = test.capitalize() print(v): Alex ...
- for_each_node(node)
遍历各个pg_data_t节点. 1.定义在include/linux/nodemask.h中 /* * Bitmasks that are kept for all the nodes. */ en ...
- HDU 4348 To the moon 主席树
题意: 给出一个长度为\(n(n \leq 10^5)\)的序列,最开始时间\(t=0\),支持下面几个操作: \(C \, l \, r \, d\):将区间\([l,r]\)每个数都加上\(d\) ...
- docker容器utf-8编码问题
locale -a export LANG=C.UTF-8 locale 在docker容器中python脚本汉字的会乱码 按照上面的方法暂时的设置下容器 编码可以解决脚本中文乱码问题