查找用于加密的密钥

发布于 2024-10-28 02:12:15 字数 1025 浏览 5 评论 0原文

我有这个伪代码:

for i = 0 ... P.length
    C[i] = P[i] XOR K[i%K];
    K[i%k] = ( K[i%k] +P[i] ) mod 64;

其中 P 是纯文本,C 是加密文本,K 是密钥,k 表示密钥 K 的长度(注意 k 和 K 的大小写不同)。

请注意,这是一项作业,但不是我的,我只是很好奇如何解决它,因为我一直喜欢加密主题。

这里的任务是如果给你 C 并且你知道有关密钥的以下信息,则推导出纯文本 P。

密钥是从此 TWL 单词列表中随机选择的单词。 0 到 999 之间的随机数将附加到所选单词的末尾。第一个字符大写的概率为 0.5。然后将小写“o”转换为“0”(零),每个“o”的概率为 0.5。类似地,每个小写“l”(ell) 都转换为“1”(一),每个“e”转换为“3”,每个“s”转换为“5”,每个“t”转换为“7”,所有这些都带有概率 0.5。

要求程序运行时间小于10秒,占用内存小于1GB。给出这个问题的班级有中档笔记本电脑,所以我会认真对待这 10 秒(尽管,因为我并没有真正解决作业,所以我没有时间限制)。

解决这个问题的好方法是什么?因为暴力在这里似乎没有任何用处。

PS IF “%”是模除法...那么“mod”也可以吗?

编辑:
纯文本 P 是取自维基百科的随机文本,其中所有非字母或数字的字符都被删除(包括空格)我几乎可以肯定每个字符都与 [a-zA-Z0-9] 匹配并且如果不匹配则删除。

编辑2:
此 .pdf 可能有助于澄清。在那里您将找到 P 输出和密钥的示例。

I have this pseudo code:

for i = 0 ... P.length
    C[i] = P[i] XOR K[i%K];
    K[i%k] = ( K[i%k] +P[i] ) mod 64;

Where P is a plain text, C is the encrypted text, K is a key and k denotes the length of the key K (note the caps is different for k and K).

Please note that this IS a homework but it ain't mine, I'm just rather curious on how to solve it since I've always liked encryption subjects.

The task here is to deduce the plain text P if you are given C and you know the following about the key.

The key is chosen as a random word from this TWL Word List. A random number between 0 and 999 is appended to the end of the chose word. With probability 0.5 the first character was capitalized. Lowercase 'o' is then converted to '0' (zero) with probability 0.5 for each 'o'. Similarly, each lowercase 'l' (ell) is converted to '1' (one), each 'e' to '3', each 's' to '5', and each 't' to '7', all with probability 0.5.

The program is required to take less than 10 seconds and consume less than 1 GB of memory. The class given this problem have mid-range laptops so I'd take those 10 seconds seriously (although, since I'm not really solving a homework I don't have time limitations).

What would be a good way to approach this problem? 'Cause it doesn't seem as if brute force is going to be of any use here.

P.S. IF "%" is modular division... then that does "mod" do?

Edit:
Plain text P is a random text taken from the Wikipedia in which all characters that aren't letters or numbers are stripped out (including spaces) I'm almost certain that each character is matched against [a-zA-Z0-9] and removed if doesn't match.

Edit 2:
This .pdf will probably help clarify. In there you will find examples of P outputs and the Key.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-11-04 02:12:15

我是必须解决这个问题的学生之一,我找到了答案,我的分数是 0.934(满分 1),我认为这对于第一次尝试来说很好。不管怎样,我不会在这里发布我的代码,因为我相信如果你真的想解决某些问题,你必须为之奋斗(我知道,我知道),但我可以给你一些关于如何解决它的提示。
在解决这个问题时您可能会注意到的一件事是,当密钥的密钥长度等于您尝试用来解密文本的密钥的密钥长度时,会出现一个特征,您会发现类似“that”的单词“and”“in”是指在英语文本中最常见的单词。如果您已经知道密钥的长度,则可以开始查找它。请记住,密钥的构造有一些规则,如果您使用这些规则,您甚至不必使用 TWL WORD LIST。稍微想一下,你会发现整个问题只是一个乘法和替换问题(至少我的方法是这样)。
我希望这些提示可以帮助必须执行此程序的人,如果您还有其他问题可以问我;)我会尽力帮助您。

I was one of the students who had to solve this problem and I found the answer, my score was 0.934 of 1, which I think it's nice for the first try. Anyway, I'm not gonna post my code here 'cause I believe if you really want to solve something you have to fight for it (I know, I know), but I can give you a few tips on how to solve it.
One thing you may notice while working on this problem, is that there's a characteristic that appears when the keylength of the Key is equal to the keylength of the key you are trying to use to decrypt the text, you will find words like "that" "and" "in" I mean the most common words you find in an English text. If you already know the length of the key you can start to look for it. Remember that there are rules for the construction of the key, if you use those rules, you don't even have to use the TWL WORD LIST. Think about it a little bit and you will see that the whole problems is just a multiplication and substitution problem (my approach at least).
I hope this tips can help someone that has to do this program, if you have another question you can ask me ;) I`ll try to help you out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文