input: 'content' of type string and 'key' of type int output: decrypted string 'content' if key not passed the method uses the key by the constructor. otherwise key = 1
(self, content, key=0)
| 104 | return ans |
| 105 | |
| 106 | def decrypt_string(self, content, key=0): |
| 107 | """ |
| 108 | input: 'content' of type string and 'key' of type int |
| 109 | output: decrypted string 'content' |
| 110 | if key not passed the method uses the key by the constructor. |
| 111 | otherwise key = 1 |
| 112 | """ |
| 113 | |
| 114 | # precondition |
| 115 | assert isinstance(key, int) and isinstance(content, str) |
| 116 | |
| 117 | key = key or self.__key or 1 |
| 118 | |
| 119 | # make sure key can be any size |
| 120 | while key > 255: |
| 121 | key -= 255 |
| 122 | |
| 123 | # This will be returned |
| 124 | ans = "" |
| 125 | |
| 126 | for ch in content: |
| 127 | ans += chr(ord(ch) ^ key) |
| 128 | |
| 129 | return ans |
| 130 | |
| 131 | def encrypt_file(self, file, key=0): |
| 132 | """ |
no outgoing calls