MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / encrypt_file

Method encrypt_file

ciphers/xor_cipher.py:132–155  ·  view source on GitHub ↗

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, key = 0)

Source from the content-addressed store, hash-verified

130
131
132 def encrypt_file(self, file, key = 0):
133 """
134 input: filename (str) and a key (int)
135 output: returns true if encrypt process was
136 successful otherwise false
137 if key not passed the method uses the key by the constructor.
138 otherwise key = 1
139 """
140
141 #precondition
142 assert (isinstance(file,str) and isinstance(key,int))
143
144 try:
145 with open(file,"r") as fin:
146 with open("encrypt.out","w+") as fout:
147
148 # actual encrypt-process
149 for line in fin:
150 fout.write(self.encrypt_string(line,key))
151
152 except:
153 return False
154
155 return True
156
157
158 def decrypt_file(self,file, key):

Callers

nothing calls this directly

Calls 1

encrypt_stringMethod · 0.95

Tested by

no test coverage detected