input: filename (str) and a key (int) output: returns true if encrypt process was successful otherwise false if key not passed the method uses the key by the constructor. otherwise key = 1
(self, file: str, key: int = 0)
| 183 | return ans |
| 184 | |
| 185 | def encrypt_file(self, file: str, key: int = 0) -> bool: |
| 186 | """ |
| 187 | input: filename (str) and a key (int) |
| 188 | output: returns true if encrypt process was |
| 189 | successful otherwise false |
| 190 | if key not passed the method uses the key by the constructor. |
| 191 | otherwise key = 1 |
| 192 | """ |
| 193 | |
| 194 | # precondition |
| 195 | assert isinstance(file, str) |
| 196 | assert isinstance(key, int) |
| 197 | |
| 198 | # make sure key is an appropriate size |
| 199 | key %= 256 |
| 200 | |
| 201 | try: |
| 202 | with open(file) as fin, open("encrypt.out", "w+") as fout: |
| 203 | # actual encrypt-process |
| 204 | for line in fin: |
| 205 | fout.write(self.encrypt_string(line, key)) |
| 206 | |
| 207 | except OSError: |
| 208 | return False |
| 209 | |
| 210 | return True |
| 211 | |
| 212 | def decrypt_file(self, file: str, key: int) -> bool: |
| 213 | """ |
nothing calls this directly
no test coverage detected