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)
| 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 | """ |