字符串加密

字符串加密

http://www.nowcoder.com/questionTerminal/e4af1fe682b54459b2a211df91a91cf3

while True:
    try:
        keys,encrypt = input().upper(),input()
        a ,table= "",{}
        alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        for i in keys:
            if i not in a:
                a += i
        newStr = a
        for i in alpha:
            if i not in newStr:
                newStr += i
        for i in range(len(newStr)):
            table[alpha[i]] = newStr[i]
        # 加密过程
        res = ""
        for i in range(len(encrypt)):
            if encrypt[i] in table.keys():
                for k,v in table.items():
                    if k == encrypt[i]:
                        res += v
            elif not encrypt[i].isalpha():
                res += encrypt[i]
            else:
                for k,v in table.items():
                    if k == encrypt[i].upper():
                        res += v.lower()
        print(res)
    except:
        break
全部评论

相关推荐

shtdbb_:还不错,没有让你做了笔试再挂你
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务