【问题标题】:decoding an ASCII character message解码 ASCII 字符消息
【发布时间】:2014-11-12 01:17:45
【问题描述】:

我不知道我需要做什么来解码mmZ\dxZmx]Zpgy,我有一个例子但不知道该怎么做请帮忙!

 If (EncryptedChar - Key < 32) then

 DecryptedChar = ((EncryptedChar - Key) + 127) - 32

Else

DecryptedChar = (EncryptedChar - Key)

我们未知的关键 1-100

【问题讨论】:

  • 我敢打赌它是 88。(而且我认为消息开头缺少 :Z。)
  • 反正哪一部分你不知道怎么办?如何遍历字符串的字符?如何将字符转换为数字并返回,以便您可以对它们进行- Key 之类的算术运算?如何将每个DecryptedChar 累积成一个字符串?

标签: decode basic


【解决方案1】:

使用 ordchr 在 ASCII 值的序数 (ord) 和它们所代表的字符 (chr) 之间进行转换。

然后您可以遍历您的字符串并将您的算法应用于每个字符串。

例如:

import sys
SecretMessage = "mmZ\dxZmx]Zpgy"
Key = 88
for Letter in SecretMessage:
    EncryptedChar = ord(Letter)
    if (EncryptedChar - Key) < 32:
        DecryptedChar = ((EncryptedChar - Key) + 127) - 32
    else:
        DecryptedChar = (EncryptedChar - Key)
    sys.stdout.write(chr(DecryptedChar))

运行它以查看输出。我将把找到关键值88 的练习留给您(提示:它涉及迭代)。您似乎还缺少来自SecretMessage 的第一个字母(可能是:)。

【讨论】:

    猜你喜欢
    • 2021-03-17
    • 2021-07-28
    • 2019-10-21
    • 2023-01-02
    • 1970-01-01
    • 2016-09-18
    • 2012-09-16
    • 2016-02-12
    相关资源
    最近更新 更多