【发布时间】:2020-07-02 20:01:46
【问题描述】:
我反向工程解密,但没有得到预期的结果。
例如输入
Lipps${svph%
偏移量为 4 的结果应该是
Hello World!
但我明白了
ello´world³
我做错了什么?
code = input("Enter text to decrypt: ")
distance = int(input("Enter number of offset: "))
plainText = ''
for ch in code:
ordValue = ord(ch)
cipherValue = ordValue - distance
if cipherValue < ord('a'):
cipherValue = ord('z') - \
(distance - (ord('a') - ordValue + 1))
plainText += chr(cipherValue)
print(plainText)
【问题讨论】:
-
你为什么使用
if cipherValue < ord('a')? -
之前做过凯撒解密/加密。您是否考虑过生成地图字典而不是尝试执行 ord 然后大写转换?这种转变是你问题的一部分。
-
我对python的了解有限,只知道课文教什么。
-
作为一个更新,我已经尝试修改我当前的代码几次,但仍然有相同的意外结果。
-
我可能对此一无所知,但我认为凯撒密码保持在相同的 a-zA-Z 范围内,那么非字母数字来自哪里?覆盖范围的上限和下限是多少?
标签: python reverse-engineering