python challenge 1

首先解码这段文本:
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.

关于解码方法,没有任何提示,不过还好比较简单,每个字母的ASCII码加2就行了。解码后的文本是:
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.

根据提示,将URL中的map再进行一次解码(同样的使用ASCII码加2,图片中的提示:K->M, O->Q, E->G 是没用的),得到ocr,过关。

import string

if __name__ == '__main__':
s = "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."

#solution 1 Star
trans = string.maketrans('abcdefghijklmnopqrstuvwxyz', 'cdefghijklmnopqrstuvwxyzab');
print(s.translate(trans))
print('map'.translate(trans))
#solution 1 End

#solution 2 Start
o = ''
for x in s:
if ord(x) >= ord('a') and ord(x) <= ord('z'):
o += chr(((ord(x) + 2 - ord('a'))) % 26 + ord('a'))
else:
o += x

print(o)

print(''.join(chr(ord(x) + 2) for x in 'map'))
#solution 2 End

#solution 3 Start
trans = string.maketrans(string.ascii_lowercase, string.ascii_lowercase[2:] + string.ascii_lowercase[0:2]);
print(s.translate(trans));
print('map'.translate(trans))
#solution 3 End



让我学习到了translate, ord, chr, string.ascii_lowercase的使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值