I have written an AES cipher in python to help me understand its implementation in software.
I am reading the file contents into a bytearray using:
with open(self.plaintext_file_path, 'rb') as f:
self.plaintext_data = bytearray(f.read())
the plaintext_data then gets run through the cipher and outputs ciphertext_data. It's then saved back to a file after the bytes have been encrypted using:
with open(fname, 'wb') as f:
f.write(self.ciphertext_data)
the file extension (for example .jpg) is maintained in the filename that I am using to save the data though the resulting file will not open as an image. why?