题解 | #字符串加密#

字符串加密

https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3

mi_yao = input()  # 密钥
s = input()  # 字符串
s1 = ""
s2 = "abcdefghijklmnopqrstuvwxyz"  # 小写字母表
s0 = s1 + mi_yao + s2  # 将密钥和小写字母表拼接
a = []
b = []
c = []
for i in s0:  # 遍历拼接的字母表
    if i not in a:  对字母表去重
        a.append(i)
t = "".join(a)  #密钥加密后的字母表(nihaobcdefgjklmpqrstuvwxyz) 
for i in s: # 遍历输入的字符串
    if i in s2:  # 如果字符串中的字母在小写字母表中
        r0 = s2.index(str(i))  # 字符串在小写字母表的索引=密钥加密后的字母表的索引(重点)
        b.append(r0)
for i in b:
    s3 = t[i]
    c.append(s3)
print("".join(c))

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务