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