Objective
Create a program in Python that encrypts an image in Windows bitmap (BMP) format. First check that it is a valid .bmp image by looking at the header data BM. If it is valid, encrypt the image by swapping the first two bytes that contain the mark BM for MB. You can open the file in r+b mode to read and write at the same time.
BMP is a Windows format that can store images of up to 24 bits (16.7 million colors). Its header starts with the type (BM) in bytes 0-1, followed by the size, the reserved bytes, the start of the image data, the width (bytes 18-21) and the height (bytes 22-25), among other fields.
Files: the file image.bmp already exists. If it starts with BM, change those two bytes to MB in the same file (do not change anything else) and print nothing. Otherwise leave the file untouched and print Not a valid BMP file.
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise