-3

我正在尝试将 ROT 13 凯撒密码用于 Python 中的大学加密分配,但我不知道如何使用它。这是我尝试过的:

def rot13(s):
    Alphabets="ABCDEFGHIJKLMNOPQRSTUVWEXYZ"
    type (Alphabets)
    Rotate=Alphabets[13:]+ Alphabets[:13]
    Reus= lambda a: Rotate[Alphabets.find(a)]
    if Alphabets.find(a)>-1:
    else: s
    return ''.join(Reus(a) for a in s)
    rot13('rageofbahamut')

是否有任何程序指南可以解释如何使用此密码?任何帮助表示赞赏。谢谢你。

4

1 回答 1

1

这将使用 ROT13 进行加密。或您希望使用的任何其他旋转值。

alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def encrypt(plain, rot):
    cipherText = ''

    for letter in plain:
        if letter in alphabet:
            cipherIndex = (alphabet.index(letter) + rot) % 26 # This handles the wrap around
            cipherText = cipherText + alphabet[cipherIndex]
        else:
            cipherText = cipherText + letter # Non alphabet characters are just appended.
    return cipherText

plain = 'HELLO WORLD'
rot = 13 # In case you want to change it
print encrypt(plain,rot)
于 2019-10-23T10:33:58.470 回答