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)
| 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): |
nothing calls this directly
no test coverage detected