【问题标题】:Word unscrambling using python使用python解扰单词
【发布时间】:2017-04-18 17:54:50
【问题描述】:

以下代码使用步长随机打乱文本,我想写一个函数来解扰并获取原始字符串如何做到这一点。

def scramble(plain):
    cipher = ""
    step = 7
    for x in range(0, step):
        for y in range(x, len(plain), step):
            cipher += plain[y]
    return cipher

【问题讨论】:

  • 它不会“随机”打乱它,它会以非常明显的模式对其进行打乱。尝试打乱字母表中的字母,从前 7 个字母开始,然后一次添加一个字母,然后查看生成的模式。寻找模式,并尝试自己编写解读函数。如果您的解密代码有具体问题,我们可以尝试提供帮助。
  • 对不起,我认出了这个模式,你能帮我弄清楚如何扭转它吗?我无法掌握它,任何线索都会被应用

标签: python words scramble


【解决方案1】:

只需反转模式:

def unscramble(cipher):
    plain = [""] * len(cipher)
    step = 7
    i = 0
    for x in range(0, step):
        for y in range(x, len(plain), step):
            plain[y] = cipher[i]
            i += 1
    return ''.join(plain)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-19
    • 1970-01-01
    • 2020-03-27
    • 2021-05-11
    • 1970-01-01
    相关资源
    最近更新 更多