python加密程序_Python加密程序
展開(kāi)全部
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'))
試試這個(gè),我發(fā)現(xiàn)你的問(wèn)題有兩個(gè):alp2num
函數(shù)有問(wèn)題,應(yīng)該再進(jìn)行62616964757a686964616fe4b893e5b19e31333337613235下mod37,并且應(yīng)當(dāng)對(duì)空格做特殊處理
key沒(méi)有使用正確使用
總結(jié)
以上是生活随笔為你收集整理的python加密程序_Python加密程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 西门子Step7和TIA软件“交叉引用”
- 下一篇: 如何创建基本的高级队列之一:创建发送方代