Skip to content
Advertisement

Why couldn’t I encrypt and decrypt a photo file using increments?

I made a very simple encryption and decryption program to encrypt files by incrementing all bytes by 6. However, in testing, only text files work. If I use it to encrypt and decrypt photos, the result is not readable by the OS.

Code in Python:

JavaScript

Advertisement

Answer

This part needs to be changed to a else :

JavaScript

Like this :

JavaScript

Otherwise, if the first if is true, the byte is changed and the second if might be runned, applying twice the increment.

Same for the decryption.

Advertisement