python - 代码不能采用“密钥”值,因此无法在凯撒密码上选择加密密钥
问题描述
我对python比较陌生。我写的初始版本有一个固定的密钥,abc.index(c)+3
可以说也是如此。我想到了一个小升级,并决定让用户输入加密密钥。现在,如果我输入加密密钥 1-4,代码会起作用,但任何东西都不会。我现在有点卡住了。
abc = "abcdefghijklmnopqrstuwxyz"
key = int(input("what is the encryption key you desire"))
plain = input("what is the word/sentence you want to encode?: ")
cipher = "";
for c in plain:
if c.isalpha() : cipher += abc[(abc.index(c)+key)%26]
else: cipher += c
print(cipher)
解决方案
将 abc 替换为
import string
abc=string.ascii_lowercase
推荐阅读
- python - 如何在缩放会议中向单个参与者发送消息?
- r - 我需要在 R 中按范围拆分表
- typescript - React Native 绝对路径似乎不起作用
- vue.js - VueJS错误:当我在本地存储中获取项目时“无法读取null属性”
- node.js - 如何在没有 vscode 的情况下运行现有的语言服务器
- java - 极端算术溢出错误背后的含义
- python - 创建链表而不初始化空节点
- javascript - Google App Script:识别代码的性能/执行速度瓶颈部分
- r - 如何将 mapply 与列表一起使用
- javascript - 删除/onDisconnect 在注销时不起作用