700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python编写加密程序_python编写的维吉尼亚密码加解密程序

python编写加密程序_python编写的维吉尼亚密码加解密程序

时间:2020-06-20 07:18:03

相关推荐

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./3280780/1726430

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。