First of all, please take a look at the two pictures. Be sure to sharpen your eyes and youyouyou –>

    

I don’t think you could have polished your big shiny titanium eyes to see the difference between these two pictures. You might just think, well, this guy is so handsome! (do not accept refutation, have ability you to hit me, ha ha, you hit me I run!! Run away!! . In fact, I hid a text message in the second picture. What exactly was hidden will be mentioned below.

The entire program uses Python and OpencV, through four main functions to achieve encryption. The functions are as follows:

(1) Encode encrypted text and save the result to input.txt file

(2) Hide the coding after word processing in the picture

(3) Obtain encrypted information from the picture, and save the text encoding to output.txt file

(4) Process the encoding information in output. TXT file to obtain the text information hidden in the picture.

Where (1) and (2) belong to the encryption process, (3) and (4) belong to the decryption process.

The whole project directory structure is shown in the figure:

In two Python script files, I have written five functions that can be called to encrypt images. Two TXT files save respectively are to be encrypted text encoded data and has been decrypted text encoded data. The content in both files is the same, but one is the input and the other is the output. The two images are the original image and the encrypted image, which are the two images I put above.

As for why you write two Python scripts, here’s the thing. I need to convert Chinese characters to binary encoding for saving, but this conversion function can only be implemented under python3. I want to encrypt the image using OpencV, but my OpencV configuration can only be used under Python2, so I wrote the function that handles the encoding of Chinese characters and the function that handles the image in two different scripts, running using Python2 and Python3 respectively.

First of all, why can’t the pictures with content be seen with naked eyes? Because the picture is composed of pixels, each pixel contains three values, respectively RGB values, and RGB values range from 0 to 255. I’m just adding or subtracting one to these values, and the gamut is so small that you don’t see it at all.

In Python, each Chinese character corresponds to a number, such as “ren”, which corresponds to the decimal number 20161, and the binary number 20161 is “100111011000001”. This is a 15-bit binary number, but some characters have 16-bit binary numbers. To ensure that every Chinese character is encoded and hidden in pixels, I use 18-bit binary numbers to hold all the text to be encrypted. One pixel can store three binary bits, so six pixels can store one Chinese character. An image with a resolution of 1024X768 can hide about 130,560 words (1024/6 x 768).

So how to hide the binary number corresponding to Chinese characters in the pixel value of the image? It looks like this. As shown in the picture, I first print out six original pixel values, and use these six pixels to hide a Chinese character.

First, the original pixel values are processed, so that all pixel values with odd values become even values, while the original even pixel values remain unchanged. The pixel values after processing are shown in the figure:

    

Now I can hide the binary value 100111011000001 corresponding to the word “ren” in the image and add each bit of binary value to the processed pixel value. After encryption, the values of these six pixels are:

    

After the above operation, the function of hiding Chinese characters is realized. If an even number is 0 and an odd number is 1, the above pixel value can be extracted as the binary number 000100111011000001. The binary can be converted into the decimal number 20161 by using the function, which can be converted into the Chinese character “ren”.

Below I post the program in the form of pictures:

A program for processing words:

Yes, the coded message in my image is “* This man is retarded, leave him alone! * “ha, ha, ha

    

Image processing procedures:

    

The program that does this has been posted on my GitHub. The link to the program is github.com/t20134297/H…