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)
m = ascii.index(plaintext)
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)
m = ascii.index(ciphertext)
if m < k:
m += 26
plaintext += ascii
i += 1
print plaintext
页:
[1]