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

Method decrypt_file

ciphers/xor_cipher.py:212–237  ·  view source on GitHub ↗

input: filename (str) and a key (int) output: returns true if decrypt 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)

Source from the content-addressed store, hash-verified

210 return True
211
212 def decrypt_file(self, file: str, key: int) -> bool:
213 """
214 input: filename (str) and a key (int)
215 output: returns true if decrypt process was
216 successful otherwise false
217 if key not passed the method uses the key by the constructor.
218 otherwise key = 1
219 """
220
221 # precondition
222 assert isinstance(file, str)
223 assert isinstance(key, int)
224
225 # make sure key is an appropriate size
226 key %= 256
227
228 try:
229 with open(file) as fin, open("decrypt.out", "w+") as fout:
230 # actual encrypt-process
231 for line in fin:
232 fout.write(self.decrypt_string(line, key))
233
234 except OSError:
235 return False
236
237 return True
238
239
240if __name__ == "__main__":

Callers

nothing calls this directly

Calls 1

decrypt_stringMethod · 0.95

Tested by

no test coverage detected