用python破解密码

看到群里同学提到阿里云《消失的三重密码》活动。然后好奇去搜了一下。

aliyun

在搜的过程中被剧透了需要使用键盘位置到字母位置的转换,即'qwer...'->'abcd...'。

那么就看看知道这个知识之后该怎么用python进行解码。

python中的sting.maketrans()函数可以生成一个转换表,之后结合string.translate()函数就可以进行字符串转换。

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.

解密代码

import string #记得导入string模块

# 题面字符串
s = "Of zit kggd zitkt qkt ygxk ortfzoeqs wqlatzwqssl qfr zvg ortfzoeqs yggzwqssl. Fgv oy ngx vqfz zg hxz zitd of gft soft, piv dgfn lgsxzogfl qkt zitkt? Zohl:hstqlt eiqfut zit ygkd gy zit fxdwtk ngx utz. Zit Hkgukqddtkl!"

# 转换的源字符和目标字符
s1 = 'qwertyuiopasdfghjklzxcvbnm' # 按键盘上的顺序
s2 = 'abcdefghijklmnopqrstuvwxyz'

table = string.maketrans(s1, s2) #制造转换列表
result = s.lower().translate(table) #进行解码
print results

得到结果

in the room there are four identical basketballs and two identical footballs. now if you want to put them in one line, jhw mony solutions are there? tips:please change the form of the number you get. the programmers!

(注意到'jhw mony'按理应该解为'how many',这里应该是出题者犯的错)

之后就是排列组合的问题了,C(6,2)=15,再转为二进制就是1111。于是答案就是1111。

results matching ""

    No results matching ""