展开全部
alp='abcdefghijklmnopqrstuvwxyz0123456789 '
def num2alp(c):
a = alp[c]
return(a)
def alp2num(d):
if d != ' ':
return((ord(d)-97)%37)
else:
return 36
def envVigenere(key,plaintext):
m = len(plaintext)
n = len(key)
etext = ""
for i in range(m):
p = plaintext[i]
k = key[i%n]
num1 = alp2num(p)
num2 = alp2num(k)
num3 = (num1+num2)%37
f = num2alp(num3)
etext = etext + f
return(etext)
print(envVigenere('lemon','attack at dawn'))
试试这个,我发现你的问题有两个:alp2num
函数有问题,应该再进行62616964757a686964616fe4b893e5b19e31333337613235下mod37,并且应当对空格做特殊处理
key没有使用正确使用