python实现维尼吉亚密码
2017-11-22 11:21
183 查看
一 代码
二 运行结果
请输入明文:tomorrowiwillhaveagood
asxzfncntzppwsorsrrrvh
请输入密文:asxzfncntzppwsorsrrrvh
tomorrowiwillhaveagood
#key='relations'
#plaintext='tomorrowiwillhaveagood'
key='helloworld'
plaintext=input('请输入明文:')
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=input('请输入密文:')
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)
二 运行结果
请输入明文:tomorrowiwillhaveagood
asxzfncntzppwsorsrrrvh
请输入密文:asxzfncntzppwsorsrrrvh
tomorrowiwillhaveagood
相关文章推荐
- 菜鸟使用python实现正则检测密码合法性
- 菜鸟使用python实现正则检测密码合法性
- python实现随机密码字典生成器示例
- Python不同电脑之间传输文件实现类似scp功能不输密码
- Python3 初学实践案例(6)终极 CLI 密码生成程序实现
- python实现linux服务器批量修改密码并生成execl
- python实现在控制台输入密码不显示的方法
- Python实现在线暴力破解邮箱账号密码功能示例【测试可用】
- python实现自动化登陆不需要密码
- Python实现LDAP用户名密码验证
- python3实现暴力穷举博客园密码
- 使用python实现简单的序列密码
- 搭建MHA,python实现服务器ssh无密码认证
- Python 实现简单的密码判断
- python+cookielib实现批量利用账号和密码自动获取新浪微博登录cookie
- Python简单实现产生随机位数的密码及注意事项小结
- python实现简单的用户密码登录控制(输入三次就锁定用户)
- 密码学学习(一) Python实现两个简单的加密算法
- python Pexpect 实现输密码 scp 拷贝
- python输入错误密码用户锁定实现方法