Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下代码使用步长随机加扰文本,我想编写一个函数来解扰并获取原始字符串如何做。
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
只需反转模式:
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)