题解 | #字符串加密#
字符串加密
http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
def mockit(code,decode):
#创建原始对照表
alpha="abcdefghijklmnopqrstuvwxyz"
alphalist=list(alpha)
code=list(code)
decode=list(decode)
#在原始对照表中找到需要解密的字符的索引位置
decodeindex=list(map(alphalist.index,decode))
#根据秘钥创建新的对照表
for i in code[::-1]:
alphalist.remove(i)
alphalist.insert(0, i)
#在新的对照表中按索引位置找到对应的加密字符
result=""
for i in decodeindex:
result+=alphalist[i]
return result
if __name__=="__main__":
print(mockit(input(), input()))
# alpha="abcdefghijklmnopqrstuvwxyz"
# alphalist=list(alpha) #原始对照表
# code=list(input())
# decode=list(input())
# decode=list(map(alphalist.index,decode))
# #需要加密的字符串在原始对照表中的index
# for i in code[::-1]:
# alphalist.remove(i)
# alphalist.insert(0,i)
# #加入密匙的新对照表
# for j in decode:
# print(alphalist[j],end="")
# #按照index在新对照表找到对应的字串