Python实现维吉尼亚密码加密解密完整示例

陆遥
陆遥
发布时间:2026-10-14 | 4人浏览过
原创

本文提供基于Python的维吉尼亚密码算法实现代码,涵盖加密与解密两个核心过程。通过示例演示如何利用密钥对明文进行循环移位加密,并对密文进行逆向还原。文中还附带了多种在线加密解密工具链接,供开发者快速测试AES、DES、MD5等算法,适合Python初学者及密码学爱好者参考。

Python维吉尼亚密码算法概述

本文详细介绍使用Python语言实现维吉尼亚密码算法的具体方法,代码示例清晰易懂,旨在为读者提供实用的参考方案。

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)

二、程序运行效果展示

相关在线加密工具推荐

此外,如果您对加密解密技术感兴趣,还可以参考本站提供的以下在线辅助工具:

文字在线加密解密工具(支持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程序设计工作有所帮助。

相关标签:

本站声明

本文内容仅供参考,不代表本站观点。转载或引用请注明出处。如发现内容问题,请通过联系我们页面反馈。

Python 相关产品和应用

全部下载

专题列表