题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
key = input()
targetStr = input()
targetStrList = list(targetStr)
resultList = []
# 处理后的key
key1 = []
# 原字母表
alphaTablet = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
]
# 更新后的新字母表
newalphaTablet = []
for word1 in key:
if word1 not in key1:
key1.append(word1)
# 将处理后的key加入到新字母表开头
newalphaTablet = newalphaTablet + key1
# 更新新字母表
for word2 in alphaTablet:
if word2 not in newalphaTablet:
newalphaTablet.append(word2)
# 替换
for i in range(len(targetStrList)):
for j in range(26):
if alphaTablet[j] == targetStrList[i]:
resultList.append(newalphaTablet[j])
continue
print("".join(resultList))