Encodes and saves a file. Creates buffers for a new file and a "quick key." Generates the "quick key." Encodes the old file onto the new file buffer. Writes the buffer to the destination. Closes the open files.
(source, destination, key)
| 176 | return key |
| 177 | |
| 178 | def work_encode(source, destination, key): |
| 179 | '''Encodes and saves a file. |
| 180 | |
| 181 | Creates buffers for a new file and a "quick key." |
| 182 | Generates the "quick key." |
| 183 | Encodes the old file onto the new file buffer. |
| 184 | Writes the buffer to the destination. |
| 185 | Closes the open files.''' |
| 186 | new_file = '' |
| 187 | encode_key = range(256) |
| 188 | for index in range(256): |
| 189 | encode_key[key[index][0]] = key[index][1] |
| 190 | for line in source: |
| 191 | for byte in line: |
| 192 | new_file += chr(encode_key[ord(byte)]) |
| 193 | destination.write(new_file) |
| 194 | source.close() |
| 195 | destination.flush() |
| 196 | destination.close() |
| 197 | |
| 198 | def decode_file(): |
| 199 | '''Decodes a file. |
no test coverage detected