这里主要是用到了python的字符串处理的转换!
import string a="g fmnc wms bgbl'r rpylqjyrc gr zw fylb. rfyr'q 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." t=string.maketrans("abcdefghijklmnopqrstuvwxyz","cdefghijklmnopqrstuvwxyzab") b=a.translate(t) print b c="map" d=c.translate(t) print "将url中的map改成:"+d
下面介绍一下别人写的高端大气的代码:
1 import string 2 text = """g fmnc wms bgbl'r rpylqjyrc gr zw fylb. rfyr'q ufyr 3 amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q 4 ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. 5 lmu ynnjw ml rfc spj.""" 6 table = string.maketrans( 7 string.ascii_lowercase,string.ascii_lowercase[2:]+string.ascii_lowercase[:2]) 8 print string.translate(text,table)
下面这段代码也是可以实现上面的功能
1 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." 2 o="" 3 for x in s: 4 if ord(x)>=ord('a') and ord(x)<=ord('z'): 5 o+=chr((ord(x)+2-ord('a'))%26+ord('a')) 6 else: 7 o+=x 8 print o