题解 | #字符串加密#
字符串加密
http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
while True: try: key=input().upper() #密钥 str1=input() #需加密字符串 zimubiao='ABCDEFGHIJKLMNOPQRSTUVWXYZ' new_key='' new_zimubiao='' new_str='' #step1:密钥去重 for x in key: if x not in new_key: new_key+=x new_zimubiao=new_key
print(new_key)
#step2:字母表重排
for y in zimubiao:
if y not in new_zimubiao:
new_zimubiao+=y
print(new_zimubiao)
#step3:字符串加密
for i in str1:
if i in zimubiao:
new_str+=new_zimubiao[zimubiao.index(i)]
else:
new_str+=new_zimubiao[zimubiao.index(i.upper())].lower()
else:
new_str+=i
print(new_str)
except:
break