如何使用python代码在字符串上实现ROT13来演示字符串加密?



我正在尝试使用 ROT 13 caeser 密码在 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')

是否有任何程序指南可以解释如何使用此密码?任何帮助,不胜感激。谢谢。

这将使用 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)

最新更新