维吉尼亚密码

维吉尼亚密码属于多表代换密码

其中A<-->0,B<-->1,...,Z<-->25,则每个密钥K相当于一个长度为m的字母串,称为密钥字。维吉尼亚密码一次加密m个明文字母。

示例:设m=6,密钥字为"CIPHER",对应数字串K=(2,8,15,7,4,17)。要加密明文为:thiscrypto,则
则相应的密文为:VPXZGIAXIV

解密时,使用相同的密钥字进行逆运算即可。

可以看出,维吉尼亚密码的密钥空间为26^m。

加密:

python 复制代码
Plaintext = 'THISCRYPTO'#字母需要大写
K = [2,8,15,7,4,17]

#print(K)#密钥

Ciphertext = ''
for i in range(len(Plaintext)):
    M_i = ord(Plaintext[i]) - 65 
    K_i = K[i%len(K)]
    C_i = (M_i+K_i)%26
    Ciphertext += chr(C_i+ 65) 
print(Ciphertext)

解密:

python 复制代码
Ciphertext = 'VPXZGIAXIV'   
K = [2,8,15,7,4,17]

Plaintext = ''
for i in range(len(Ciphertext)):
    C_i = ord(Ciphertext[i]) -65 
    K_i = K[i%len(K)]
    M_i = (C_i - K_i)%26
    Plaintext += chr(M_i+ 65) 
print(Plaintext)
相关推荐
dagouaofei2 分钟前
不同 AI 生成 2026 年工作计划 PPT 的使用门槛对比
人工智能·python·powerpoint
itwangyang5208 分钟前
Windows + Conda + OpenMM GPU(CUDA)完整安装教程-50显卡系列
人工智能·windows·python·conda
weixin_4450547219 分钟前
力扣热题52
开发语言·python
mengyoufengyu20 分钟前
JupyterLab4.5安装使用
python·jupyter·jupyterlab
weixin_4624462321 分钟前
Python 使用阿里云 STS 获取临时访问凭证并上传文件至 OSS:Flask API 实现
python·阿里云·flask
橙露25 分钟前
从零基础到实战:Python 数据分析三剑客(Pandas+NumPy+Matplotlib)核心应用指南
python·数据分析·pandas
一勺菠萝丶27 分钟前
Java 对接 PLC 实战:西门子 PLC 与永宏 PLC 通讯方式全面对比
java·开发语言·python
这就是佬们吗30 分钟前
Windows 的 CMD 网络环境:解决终端无法联网与更新的终极指南
java·windows·git·python·spring·maven
栈与堆30 分钟前
数据结构篇(1) - 5000字细嗦什么是数组!!!
java·开发语言·数据结构·python·算法·leetcode·柔性数组
企鹅会滑雪33 分钟前
【无标题】
开发语言·python