python编写加密程序_python编写的维吉尼亚密码加解密程序
維吉尼亞密碼表
=============================================
#維吉尼亞密碼 加密
key=‘helloworld‘
plaintext=‘whereisthekey‘
#key=‘relations‘
#plaintext=‘tobeornottobeth‘
ascii=‘abcdefghijklmnopqrstuvwxyz‘
keylen=len(key)
ptlen=len(plaintext)
ciphertext = ‘‘
i = 0
while i < ptlen:
j = i % keylen
k = ascii.index(key[j])
m = ascii.index(plaintext[i])
ciphertext += ascii[(m+k)%26]
i += 1
print ciphertext
===================================================================
#維吉尼亞加密算法 解密
key=‘helloworld‘
ciphertext=‘dlpcsegkshrij‘
#key=‘relations‘
#ciphertext=‘ksmehzbblk‘
ascii=‘abcdefghijklmnopqrstuvwxyz‘
keylen=len(key)
ctlen=len(ciphertext)
plaintext = ‘‘
i = 0
while i < ctlen:
j = i % keylen
k = ascii.index(key[j])
m = ascii.index(ciphertext[i])
if m < k:
m += 26
plaintext += ascii[m-k]
i += 1
print plaintext
原文:http://whbill.blog.51cto.com/3280780/1726430
總結
以上是生活随笔為你收集整理的python编写加密程序_python编写的维吉尼亚密码加解密程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python用二分法求平方根_Pytho
- 下一篇: 图像内复制粘贴篡改取证matlab_[论