python - 无法对替换密码进行编码
问题描述
我正在尝试制作一个基本的密码,但我一直坚持如何让它对数据进行编码和解码。这是我到目前为止所拥有的:
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
key = "XPMGTDHLYONZBWEARKJUFSCIQV"
alpha = list(alpha)
print("secret decoder menu")
def encode(key, alpha):
keyIndices = [alpha.index(k.lower()) for k in alpha]
return ''.join(key[keyIndex] for keyIndex in keyIndices)
plain = input("text to be encoded: ")
print(encode(plain, key))
我不断收到此错误:
File "/home/Deshwill/.pythonstartup.py", line 46, in <module>
main()
File "/home/Deshwill/.pythonstartup.py", line 32, in main
print(encode(plain, key))
File "/home/Deshwill/.pythonstartup.py", line 11, in encode
keyIndices = [alpha.index(k.lower()) for k in alpha]
File "/home/Deshwill/.pythonstartup.py", line 11, in <listcomp>
keyIndices = [alpha.index(k.lower()) for k in alpha]
ValueError: substring not found
解决方案
推荐阅读
- php - 如何知道codeigniter 4中的分页总页数
- javascript - 有一个纯阶级的概念是否有意义?
- tableau-api - 如何部署/托管 Tableau 扩展
- json - MongoDB 的 json.loads() 问题
- macos-sierra - 为什么一个蒸汽“你好”项目在 Sierra 启动后就被粉碎了?
- c# - 如何从触摸板获取鼠标滚动?
- homebrew - 如何修复在 Mac Mojave 中安装 xmgrace 时出现的错误?
- sql - 在 WHILE LOOP 中插入记录时发生的奇怪的 TRY CATCH 行为
- d3.js - D3js 使用手动绘制的圆圈进行缩放
- javascript - Javascript点击切换