美文网首页
c05ex08.py

c05ex08.py

作者: 特丽斯纳普 | 来源:发表于2018-03-30 20:32 被阅读0次
# c05ex08.py
#    Caesar cipher (circular version)


def main():
    print("Caesar cipher")
    print()

    key = int(input("Enter the key value: "))
    plain = input("Enter the phrase to encode: ")

    chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz"

    cipher = ""
    for letter in plain:
        pos = chars.find(letter)
        newpos = (pos + key) % len(chars)
        cipher = cipher + chars[newpos]

    print("Encoded message follows:")
    print(cipher)

main()

相关文章

网友评论

      本文标题:c05ex08.py

      本文链接:https://www.haomeiwen.com/subject/sfqwcftx.html