题解 | #字符串加密#
字符串加密
http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
# -*-coding:utf-8-*-
import string
while True:
try:
input_1,input_str = input(),input() #输入一个单词,以及要加密的明文str
str_a = list(string.ascii_lowercase) #生成明文组
str_plain = ''.join(str_a)
str_key_1 = sorted(list(set(input_1)) , key=input_1.index) #给单词去重
str_key_2 = ''.join(str_key_1)
str_b = ''
for i in str_a:
if i not in str_key_1:
str_b += i
str_key = str_key_2 + str_b #形成秘文组
for s in input_str: #生成密文
x = str_plain.index(s)
print(str_key[x] , end='')
print()
except:
break