题解 | #字符串加密#
字符串加密
http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
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
T R A I L B Z E S C D F G H J K M N O P Q U V W X Y
可以看出,这两排字母,index 一致的,就是对应的原文和密文
word = input().upper()
passwd = input()
upper_letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lower_leeters = upper_letters.lower()
keys = []
for i in word + upper_letters:
if i not in keys:
keys.append(i)
upper_keys = "".join(keys)
lower_keys = upper_keys.lower()
r = []
for i in passwd:
if i in upper_letters:
r.append(upper_keys[upper_letters.index(i)])
elif i in lower_leeters:
r.append(lower_keys[lower_leeters.index(i)])
else:
r.append(i)
print("".join(r))