The Hackr

Encrypt and Decrypt Images Using Python

Hello fellow Hackrs. Ever wonder how to encrypt images and decrypt images in Python. Today we’re gonna learn a simple python library for encrypting images. It uses a 2-key permutation system to biject the pixels in the input image. It acts on each on every pixel of the image so that, technically no one could steal the data.

There are lot of ways to encrypt images in Python. Python has inbuilt library called PyCrypto which utilizes AES encryption to achieve the encryption.
Anyway we are hereby providing the code which makes it much easier and quick to encrypt images on the go!


STEP1Download the Script

Click here to download or clone the script from this Github repo of James Lucas.

STEP2Extract the Script

Now that you have downloaded the .zip file of the encryption script, extract the ImageEncryptor folder to any directory using archive manager.

STEP3Encrypting Images

Navigate to the folder where you have extracted the required folder. In my case it’s Desktop. So navigate to Desktop by typing

cd /Desktop/

Take any test image for performing encryption and decryption tasks.

Lets take a test image of an aircraft

test image

Now encrypt any image by typing

python -e test.png -o encrypted.png 123 456
  • test.png -> image which is to be encrypted
  • encrypted.png -> name of the output encrypted image file
  • 123 -> key1
  • 456 -> key2
Output will be something similar to

image encryption
Better encrypt image to .png to avoid losing quality while decryption.

STEP4Decrypting Images

Now let’s decrypt the image which we’ve encrypted in the previous step simply by typing

python -d encrypted.png -o decrypted.png 123 456

  • encrypted.png -> image which is already encrypted
  • decrypted.png -> name of the output decrypted image file
  • 123 -> key1
  • 456 -> key2
Decrypted image will look like the original test image

decrypted image
If the decryption keys are entered incorrectly, the output image would get corrupted since the operation is done on every pixel of the image.
The disfigured would look something like
false decrypted image


The hacking trend these days has definitely turned criminal because of e-commerce ¯\_(ツ)_/¯