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

Method decrypt

XORcipher/XOR_cipher.py:56–79  ·  view source on GitHub ↗

input: 'content' of type list and 'key' of type int output: decrypted string 'content' as a list of chars if key not passed the method uses the key by the constructor. otherwise key = 1

(self, content, key)

Source from the content-addressed store, hash-verified

54 return ans
55
56 def decrypt(self, content, key):
57 """
58 input: 'content' of type list and 'key' of type int
59 output: decrypted string 'content' as a list of chars
60 if key not passed the method uses the key by the constructor.
61 otherwise key = 1
62 """
63
64 # precondition
65 assert isinstance(key, int) and isinstance(content, list)
66
67 key = key or self.__key or 1
68
69 # make sure key can be any size
70 while key > 255:
71 key -= 255
72
73 # This will be returned
74 ans = []
75
76 for ch in content:
77 ans.append(chr(ord(ch) ^ key))
78
79 return ans
80
81 def encrypt_string(self, content, key=0):
82 """

Callers 1

test_decryptMethod · 0.80

Calls 1

appendMethod · 0.45

Tested by 1

test_decryptMethod · 0.64