MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / decrypt

Method decrypt

ciphers/onepad_cipher.py:39–58  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

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
61if __name__ == "__main__":

Callers 1

onepad_cipher.pyFile · 0.45

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected