-1

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

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
4

1 回答 1

0

只需反转模式:

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)
于 2016-12-05T05:21:30.903 回答