比较Low的解密方案:
根据图形可以知道他们之间的对应关系。(映射关系)
# -*- coding:utf-8 -*-
# **********************************
# ** http://weibo.com/lixiaodaoaaa #
# ** create at 2017/6/11 00:09 ***
# ****** by:lixiaodaoaaa ***********
import string
def myTrans(letter):
if len(letter.strip()) < 1:
return " "
if letter == "y":
return "a"
if letter == "z":
return "b"
if letter == ".":
return "."
letterCode = ord(letter)
return chr(letterCode + 2)
myStr = "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."
resultStr = ""
print(myTrans(" "))
print("purpose", ord("a"))
print(ord("y"))
print(ord("z"))
这样的并不完美。我们看一下比较进阶的解决方法:【5行代码搞定!】
# -*- coding:utf-8 -*-
# **********************************
# ** http://weibo.com/lixiaodaoaaa #
# ** create at 2017/6/11 00:57 ***
# ****** by:lixiaodaoaaa ***********
import string
old_url = "http://www.pythonchallenge.com/pc/def/map.html"
if __name__ == '__main__':
table1 = "abcdefghijklmnopqrstuvwxyz"
table2 = "cdefghijklmnopqrstuvwxyzab"
new_table = string.maketrans(table1, table2)
newStr = string.translate("map", new_table)
print old_url.replace("map", newStr)