Function to decrypt text using pseudo-random numbers. >>> Onepad().decrypt([], []) '' >>> Onepad().decrypt([35], []) '' >>> Onepad().decrypt([], [35]) Traceback (most recent call last): ... IndexError: list index out of range
(cipher: list[int], key: list[int])
| 37 | |
| 38 | @staticmethod |
| 39 | def decrypt(cipher: list[int], key: list[int]) -> str: |
| 40 | """ |
| 41 | Function to decrypt text using pseudo-random numbers. |
| 42 | >>> Onepad().decrypt([], []) |
| 43 | '' |
| 44 | >>> Onepad().decrypt([35], []) |
| 45 | '' |
| 46 | >>> Onepad().decrypt([], [35]) |
| 47 | Traceback (most recent call last): |
| 48 | ... |
| 49 | IndexError: list index out of range |
| 50 | >>> random.seed(1) |
| 51 | >>> Onepad().decrypt([9729, 114756, 4653, 31309, 10492], [69, 292, 33, 131, 61]) |
| 52 | 'Hello' |
| 53 | """ |
| 54 | plain = [] |
| 55 | for i in range(len(key)): |
| 56 | p = int((cipher[i] - (key[i]) ** 2) / key[i]) |
| 57 | plain.append(chr(p)) |
| 58 | return "".join(plain) |
| 59 | |
| 60 | |
| 61 | if __name__ == "__main__": |