题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
def encode(string, key):
head = ""
# 得到不重复的头字符串
for c in key:
if c not in head:
head += c
base_str = "abcdefghijklmnopqrstuvwxyz"
encrypt_str = head
# 得到加密字符串
for c in base_str:
if c not in encrypt_str:
encrypt_str += c
# 得到对应字典
encode_dict = {}
for i in range(26):
encode_dict[base_str[i]] = encrypt_str[i]
res = ""
for c in string:
res += encode_dict[c]
return res
while True:
try:
key = input()
string = input()
print(encode(string, key))
except:
break
