温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Python实现的维尼吉亚密码算法示例

发布时间:2020-09-24 02:40:17 来源:脚本之家 阅读:152 作者:chengqiuming 栏目:开发技术

本文实例讲述了Python实现的维尼吉亚密码算法。分享给大家供大家参考,具体如下:

一 代码

# -*- coding:utf-8 -*-
#key='relations'
#plaintext='tomorrowiwillhaveagood'
print("亿速云测试结果:")
key='helloworld'
plaintext=raw_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=raw_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)

二 运行结果:

Python实现的维尼吉亚密码算法示例

PS:关于加密解密感兴趣的朋友还可以参考本站在线工具:

文字在线加密解密工具(包含AES、DES、RC4等):
http://tools.jb51.net/password/txt_encode

MD5在线加密工具:
http://tools.jb51.net/password/CreateMD5Password

在线散列/哈希算法加密工具:
http://tools.jb51.net/password/hash_encrypt

在线MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160加密工具:
http://tools.jb51.net/password/hash_md5_sha

在线sha1/sha224/sha256/sha384/sha512加密工具:
http://tools.jb51.net/password/sha_encode

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python加密解密算法与技巧总结》、《Python编码操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总》

希望本文所述对大家Python程序设计有所帮助。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI