4.1. Encryption Process
The flow chart of the encryption process is shown in
Figure 7. Given an
color plaintext image I, the encryption steps are as follows:
Step 1: Input the color plaintext image I and the customized string keyStr, and convert its keyStr to UTF-8 byte format.
Step 2: Read the binary data imgData of I and splice the keyStr to the front of imgData to obtain the spliced data cData.
Step 3: To ensure data integrity and prevent arbitrary tampering, use the SHA-256 algorithm to generate a 32 byte digest hash for cData.
Step 4: Extract the byte segments whose indices are located in the range of to in the hash and convert them to the 32-bit unsigned integer decV.
Step 5: Map decV to the range 0–10 and retain four decimals places; hence, the key sequence keys are generated. Select six of the eight values as the keys. The formula is
Step 6: Output key sequence
. The key sequence keys are used as the initial condition of the chaotic system (
14). Call the ODE45 program under the conditions of a relative tolerance of
and an absolute tolerance of
. Set the step size to 0.01, discard the first 500 values, and calculate the total time
.
Step 7: Diffusion encryption is based on the probabilistic diffusion model for the forward diffusion process of noise injection. Set the total number of diffusion steps to .
Step 8: Generate sequence , where sequence controls the noise increment at each time step. Use a chaotic system to generate T elements of sequence , arranged in ascending order and satisfying the condition .
Step 9: Obtain the sequence from . The sequence represents the mixing ratio of the data. Because the diffusion probability model is a Markov chain process, it can be used without iterative diffusion, and the closed-form solution at any time step can be obtained using the reparameterization technique to directly inject the final noisy image into images, whereupon we can pre-accumulate the concatenated multiplications and obtain the value of the cumulative T-steps of the -sequence using .
Step 10: Generate the noisy image. Use the key sequence keys as the initial value of the chaotic system (
14) and select its first state variable
x to generate the sequence to obtain the pseudo-random sequence
. Then, add a small perturbation to the initial value keys to ensure the independence of the pseudo-random sequence, obtain the initial value
, and generate the pseudo-random sequence
with
k as the initial value of the chaotic system (
14), where
is a hyperchaotic sequence generated by the sixth state variable
.
Step 11: Using sequences and , generate the Gaussian-distributed noise sequence via the Box–Muller transform formula, and use the sequence N normalized to the range to generate the noise image that accumulates up to T time steps. The noise image is also a color image of . Repeat the above steps to generate sufficient noisy images.
Step 12: Inject noise. This process is a noise diffusion operation performed in the fractional domain. First, normalize the plaintext image I to the range
to obtain the value
at step 0 of the diffusion process, and then diffuse the noise image
accumulated up to the time step T into
. Thus, a closed-form solution of the time step T is obtained using the reparametrization technique; that is, the image
after the injection of noise, which is defined in the process
Step 13: In the confusion encryption stage, because confusion encryption is a differential encryption operation based on bitwise operations, first convert the image after noise injection to Uint8 format to obtain the adjusted image .
Step 14: Generate a sequence using key sequence keys as the initial values of the chaotic system (
14) and select its second state variable y, mapping it to the
range and converting to Uint8 format to obtain the
dissimilarity sequence S.
Step 15: Perform the XOR operation on the pixel values of all three channels of the image using the XOR operation:
Step 16: Get the final image converted to Unit8.
Step 17: To break the correlation between the three RGB channels, scramble
. Because the image has 8 bits for one pixel and three channels, it can be disassembled into 24-bit planes. In this paper, we preset 24!-10 disassembling methods, such as [14, 3, 22, 9, 17, 5, 24, 12, 7, 19, 2, 16, 8, 21, 11, 4, 23, 15, 6, 13, 20, 1, 18, 10]. The selection of rules is controlled by chaotic sequences. Using the preset exchange rules, rearrange the 24-bit planes in random order. Then, within each bit plane, first use the Zigzag method to extract the bit plane into a one-dimensional bit sequence from the top-left corner. Next, place the sequence back into the bit plane according to the rule of bottom-to-top and right-to-left. Repeat this internal scrambling process three times and then the image
encrypted after the bit plane is obtained. Encryption is complete.
Figure 8 is the Zigzag scrambling and inverse transform operation diagram.
4.2. Decryption Process
The flow chart of the decryption process is shown in
Figure 9.
The decryption step is the inverse process of the encryption step. Given an ciphertext image , the decryption step is as follows:
Step 1: Input the ciphertext image and the corresponding key keys.
Step 2: Follow the inverse method of bit-plane scrambling to recover to before bit-plane scrambling.
Step 3: For XOR reduction, use the key sequence keys as the initial values of the chaotic system (
14), select its second state variable
y to generate the sequence, map it to the range
, and convert it to the uint8 format to obtain the XOR-sequence S of
, which is the same as that at the time of encryption. The XOR-reduced image
is obtained by the XOR operation. XOR operation equation is as follows:
Step 4: For diffusion reduction, generate a sequence identical to the encryption using a chaotic system. Obtain the sequence from , obtain the value of the accumulated T steps of the -sequence using , and obtain the value of the accumulated T steps of the -sequence .
Step 5: Generate the sequence using the key sequence keys as the initial values of the chaotic system (
14) and select its first state variable
x. Because the key and the key in encryption are phase diagrammed, the same pseudo-random sequences
and
can be obtained.
Step 6: Generate the noisy image using the Box–Muller transform formula and normalize it to the range of . The noisy image is the same as that used for encryption.
Step 7: Normalize the image
and then use the diffusion formula corresponding to the reduction formula:
Step 8: Obtain the decrypted and restored image , convert it back to Uint8 format, and output the decrypted and restored image .