- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我进行了逆向解密,但没有得到预期的结果。
例如,输入
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)
最佳答案
好的,我让它适用于 a-z 并为您提供了一个小测试框架来自动输入/检查,而不是每次都输入。
def dowork(code, distance, lower, upper):
bounddown, boundup = ord(lower), ord(upper)
plaintext = ""
for ch in code:
ordValue = ord(ch)
cipherValue = ordValue - distance
if cipherValue < bounddown:
cipherValue = boundup - bounddown - ordValue +1
plaintext += chr(cipherValue)
return plaintext
dataexp = [
(("jgnnq",2, 'a', 'z'),"hello"),
]
for input_, exp in dataexp:
got = dowork(*input_)
msg = "exp:%s:%s:got for %s" % (exp, got, inp)
if exp == got:
print("good! %s" % msg)
else:
print("bad ! %s" % msg)
这会打印
good! exp:hello:hello:got for ('jgnnq', 2, 'a', 'z')
现在您需要做的就是向 dataexp 列表中添加一个额外的项目,例如
(("Lipps${svph%", 4, <lowerbound>, <upperbound char>), "Hello World!")
一旦你弄清楚了上限和下限,它就应该可以工作。请注意,我不知道凯撒代码,我只是直接复制了你的代码,但对其进行了一些重组。
什么*_input
所做的就是获取该元组(或多或少是一个列表)中的这 4 个值并将它们分配给 code, distance, lower, upper
在 dowork
功能。
lower
对应于a
在你的代码和 upper
是 z
.
exp 是您所期望的并且 exp == got
只是检查函数返回的内容是否正确。一旦你得到正确的函数,它应该适用于两者我的简单化 a-z
, 2 距离, hello
测试和更复杂的 4 距离,但包括标点符号
您的 2 个字符串(输入和输出)是 Lipps${svph%
和Hello World!
。这意味着所有这些字符都需要落在您的上限和下限值内,对吧?所以所有这些的最小顺序位置是你的 lower
最大值是你的 upper
。现在,我不是密码学里的那个人,我不记得是否 ord(a) < ord(A) ,更不用说标点符号了。所以你必须对此进行修改,这就是为什么我只基于小写字母进行测试。不过我会添加 0-9。
这不需要您弄清楚将哪个字符放在最低边界以及将哪个字符放在上限。我们采用 lower = 32(可打印字符的开头),upper = 255。这样标点符号、大小写、数字及其 ord 值就不再重要了。
#full ASCII range, you can go to town on entering whatever you want
bounddown, boundup = 32, 255
plaintext = ""
for ch in code:
ordValue = ord(ch)
cipherValue = ordValue - distance
if cipherValue < bounddown:
cipherValue = boundup - bounddown - ordValue +1
plaintext += chr(cipherValue)
关于python - 逆向工程凯撒密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60795235/
我有 *.ipa 文件,它是 iphone 应用程序。 是否可以在该 ipa 中使用逆向工程并提取代码..? 最佳答案 嗯,这不是真正的黑客攻击,但它确实可以帮助您识别 UI 的某些部分...请执行以
我一直在尝试对游戏的功能进行逆向工程,但我有点困惑。我对逆向工程还很陌生(顺便说一句,我正在使用 ollydbg),所以我还不太了解所有的技巧和细节。 无论如何这是我的问题。当您在游戏中拾取任何元素时
我被要求抓取一个 Flash 网站,该网站似乎正在通过 AMF 协议(protocol)使用某种服务器端调用。我完全不熟悉这个协议(protocol),但找到了这个库(http://www.pyamf
我的问题是我正在使用一个巨大的网络应用程序(学校系统),没有内部逻辑的文档。我需要对特定值进行批量更新,但我不知道MySQL数据库中的哪些表包含要更新的相关数据。该应用程序是从 php 自行运行的。有
我正在学习如何逆向一个程序,我想知道..如果我用调试信息编译: gcc -g .... 这对逆向过程有什么帮助吗?如果我这样做,我会提供额外的信息吗?我找不到有关该主题的任何信息。 最佳答案 它通过将
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 5 年前。
今天我决定使用 IDA Pro 反编译一个用 Visual C++ 编写的简单“Hello world”程序。 根据我以前的知识,我确定我不会在可执行文件入口点找到对 printf 的立即调用,我是对
我正在使用 PowerDesigner 为我的 SQL Server 数据库建模。我使用逆向工程选项来导入我的数据库。我的问题是表中的默认数据未导入。 有人知道如何导入表格中的数据吗? 最佳答案 我们
我一直在分析一些 230V 通信并试图找出协议(protocol)的校验和算法。从我了解到的通信结构如下: 第一个 block 总是相同的,必须是某种开始结构(910hex) 然后嵌套5个 block
在 AmigaOS 中的 Devs:Monitors 中找到的文件,它们包含什么? 它们的内部格式是什么?您如何修补一个或从头开始创建一个? 最佳答案 Amiga 程序 MonEd ( http://
我正在使用 VS2013 更新 3 的“逆向工程”模型优先功能从现有数据库开发 EF 模型。不幸的是,我无法完全控制数据库架构,它使用表和列前缀(例如 tblPerson , cFirstName,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在尝试对 APK 文件进行逆向工程。 我尝试了 apk2jar 来获取类和资源文件。但我无法解压缩 Assets 。 有人可以帮忙吗? 最佳答案 使用 apktool。它将对所有布局、值、 Ass
我正在尝试解码由 Android instagram 应用程序发送到 graph.instagram.com 的帖子数据。该问题与此处发现的问题类似: Reverse Engineer HTTP re
我想查明用 C/C++ 编写的应用程序究竟在哪里失败。我无法直接调试应用程序,既不使用 gdb/lldb 也不使用 IDE,因为应用程序是由程序启动的(它是 webots 机器人模拟软件的机器人 Co
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找书籍、工具、软件库、教程或其他场外资源的问题对于 Stack Overflow 来说是
我有一个最初用 VS2005 编写的小实用程序。 我需要做一点小改动,但是其中一个 dll 的源代码在某处丢失了。 是否有免费或价格合理的工具将 dll 反向工程回 C++ 代码。 最佳答案 Hex-
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我想知道是否有人知道如何对 Access 数据库进行逆向工程。我希望能够生成用于创建数据库表并将所有记录插入表中的 SQL 代码。换句话说,我想创建类似于 MySQL 转储文件的内容。 任何想法都会很
String.GetHashCode 的行为取决于程序架构。所以它将在 x86 中返回一个值,在 x64 中返回一个值。我有一个必须在 x86 上运行的测试应用程序,它必须预测必须在 x64 上运行的
我是一名优秀的程序员,十分优秀!