MCPcopy Create free account
hub / github.com/ActiveState/code / work_encode

Function work_encode

recipes/Python/456374_Crypt/recipe-456374.py:178–196  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

176 return key
177
178def 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
198def decode_file():
199 '''Decodes a file.

Callers 1

encode_fileFunction · 0.85

Calls 4

rangeFunction · 0.85
writeMethod · 0.45
closeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected