MCPcopy Create free account
hub / github.com/geekcomputers/Python / encrypt_file

Method encrypt_file

XORcipher/XOR_cipher.py:131–153  ·  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

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

Callers 1

test_encrypt_fileMethod · 0.80

Calls 1

encrypt_stringMethod · 0.95

Tested by 1

test_encrypt_fileMethod · 0.64