# Sequence test for an image cipher

I am reading a paper on security analysis of a cipher image using the paper at the following URL:

https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=8306512&tag=1

It indicates some test that a cipher image should pass for successful encryption. One of the simple test is to count the number of ones and number of zeros in the BINARY SEQUENCE of the image, and they should be equal, i.e 0.5 roughly of the total: How is it possible to get a proper binary sequence representation of the image? Do I just convert each bit into its binary representation and form a binary sequence, do I have to do something else?

• What does it mean to convert a bit into a binary representation? Bits are already a binary representation. Was that by any chance supposed to read "...convert a byte into a binary representation"? – Ella Rose Sep 5 '18 at 16:44
• i meant conversion each pixel into it's eight bit reprsentation – user311790 Sep 5 '18 at 16:47

It's simple. Lena is 512 x 512 pixels with a bit depth of 8. So you simply export the raw image to a file that will be exactly 262,144 bytes long. It's critical that you export or save the image as a raw binary file, not one of those JPEGey things. That won't work.

To determine the two chi values, you then consider the file as a series of consecutive individual bits, or as pairs of bits. This will entail a load of bit shifting /masking operations in your favourite programming language.

A tip. Install ent, and just run it twice against the encrypted Lena file. Run one, use the -b option which will treat the file as a series of bits. The output will produce a chi and p value. Run again without the b option. This will process the file as a series of 8 bit values. If the encryption produces independent (non correlated) bits, they can be lumped into four pair groups and treated as octets. Assume the same 5% confidence value, and look at the returned chi value to see if it's acceptable. You'd expect $219 \leq \chi^2 \leq 293$ for randomly distributed octets.

ent will also give you the Shannon entropy of the images for comparison with those in the paper.

Another tip. Do not assume that a chi failure means the encryption fails. Randomness is pesky and you have to try the test several times on repetitive images or keys.

• How exactly do you get the Shannon entropy from a single image? Entropy is a property of a method of generating data, not of the raw data itself. – forest Sep 10 '18 at 1:57
• @forest Arrrrgh! – Paul Uszak Sep 10 '18 at 3:17
• Care to elaborate? It seems like you are misunderstanding the definition of entropy again. – forest Sep 10 '18 at 3:18
• @forest I think that I've solved your problem, but it's going to require you accepting a paradigm shift. I suggest we call it known entropy and unknown entropy. Do you concur? – Paul Uszak Sep 10 '18 at 3:27
• Are you perhaps talking about, Information entropy vs Kolmogorov complexity? – forest Sep 10 '18 at 3:40