A JPEG image encryption method based on coefficient grouping encryption
By performing modulo operations on the DC coefficients of JPEG images and classifying and scrambling the AC coefficient groups for encryption, an adaptive key is generated for block scrambling. This solves the problems of non-universality and low feature change rate caused by overflow processing in JPEG image encryption methods, and achieves high-security and universal JPEG image encryption.
Patent Information
- Application Number
- CN202310103901.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-09
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2043-02-09
AI Technical Summary
Existing JPEG image encryption methods, while ensuring format compatibility and small file increments, struggle to simultaneously improve feature change rate to enhance the security of encrypted images. Furthermore, they suffer from issues such as algorithm incompatibility due to overflow handling and low feature change rate.
A coefficient-based group encryption method is adopted. By performing prediction error modulo operation on DC coefficients and classifying and scrambling AC coefficient groups for encryption, an adaptive key is generated for block scrambling to avoid overflow and improve feature change rate.
It achieves JPEG image encryption without overflow processing, improves the versatility of encryption and decryption and the ability of encrypted images to resist statistical model attacks, ensures that file size changes are within a controllable range, and is applicable to different image types.
Smart Images

Figure CN116208768B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing, specifically including a JPEG image encryption method based on coefficient grouping encryption. Background Technology
[0002] With the development of the internet, digital images have emerged and are stored and transmitted online. JPEG images, due to their small file size, have become the most widely used image format. Currently, JPEG images circulating online are plaintext images, which cannot guarantee their privacy and security. Therefore, researchers are dedicated to studying encryption methods for JPEG images to achieve image confidentiality.
[0003] The goal of JPEG image encryption methods is to achieve a secure encryption method that conforms to the JPEG standard without increasing the burden of image transmission and storage. In 2018, He et al. proposed a JPEG image encryption method with unchanged file size and format compatibility. This method uses image features to adaptively generate permutation keys, so that different images have different permutation keys. Although this algorithm improves the ability of encrypted images to resist known-plaintext attacks, it is vulnerable to chosen-plaintext attacks because the image features used to generate the permutation keys remain unchanged before and after encryption. To further increase the security of encrypted images, Qin et al. proposed a JPEG encryption method with adaptive DC coefficient prediction and RS scrambling. Compared with other existing JPEG encryption methods, this method can achieve a higher feature change rate while ensuring format compatibility and small file increment. However, this method is limited by the embedding capacity during overflow processing, and the change rates of the feature values of the position of the last nonzero AC coefficient (PLZ), the number of nonzero AC coefficients (NCC), and the energy of AC coefficients (EAC) within the block are relatively small, especially NCC. In addition, overflow handling also leads to poor algorithm versatility. Designing a JPEG encryption scheme that simultaneously achieves small file increments, format compatibility, and a high feature change rate is of significant practical value. How to improve the security of encrypted images by increasing the feature change rate while ensuring format compatibility and small file increments is a crucial challenge that must be addressed for the practical application of JPEG image encryption technology. Summary of the Invention
[0004] To address the aforementioned shortcomings in existing technologies, this invention provides a JPEG image encryption method based on coefficient grouping encryption, which solves the problems of algorithm incompatibility and low feature change rate caused by overflow processing in existing technologies.
[0005] To achieve the above-mentioned objectives, the technical solution adopted by this invention is: a JPEG image encryption method based on coefficient grouping encryption, comprising the following steps:
[0006] S1. Read the quantization table, Huffman coding table, and entropy-coded stream of DCT coefficients of the JPEG image to be encrypted;
[0007] S2. Parse the entropy coding stream of the DCT coefficients according to the Huffman coding table to obtain the original DC coefficient differential entropy coding and AC coefficient entropy coding of all blocks.
[0008] S3. Obtain the original DC coefficients based on the differential entropy encoding of the original DC coefficients, and predict the DC coefficients to obtain the DC prediction error value;
[0009] S4. Obtain and use the initial key K to scramble and encrypt the AC coefficient groups containing the complete AC coefficient entropy encoding, and obtain the encrypted AC coefficients.
[0010] S5. Extract image features F based on the AC coefficient group scrambling encryption result containing complete AC coefficient entropy encoding;
[0011] S6. Generate an adaptive key KA related to the image content using the initial key K and image features F;
[0012] S7. Using the adaptive key KA, for Perform block scrambling encryption to obtain the encrypted AC coefficient.
[0013] S8. Using the quantization table of the JPEG image to be encrypted and the adaptive key KA, positiveize the DC prediction error and perform modulo encryption to obtain the encrypted DC coefficients.
[0014] S9, DC coefficient for encryption and AC coefficient Entropy encoding is performed to obtain an encrypted image.
[0015] Furthermore, step S3 is implemented as follows:
[0016] S3-1. Obtain the original DC coefficients based on the differential entropy encoding of the original DC coefficients;
[0017] S3-2. Decode all blocks of the JPEG image to be encrypted into pixels;
[0018] S3-3. Use the 8 pixels adjacent to the target block in the block to the left and the block above the current block to predict the DC coefficient value.
[0019] S3-4. Subtract the predicted DC coefficient value from the original DC coefficient value to obtain the DC prediction error value.
[0020] Furthermore, step S4 is implemented as follows:
[0021] S4-1. Obtain j AC coefficients of different frequencies based on AC coefficient entropy encoding;
[0022] S4-2. Obtain the AC coefficient set based on the AC coefficients, where the AC coefficient set is {a i,j-l+1 ,...,a i,j} represents the set of AC coefficients with an endpoint frequency of j and an initial frequency of j-l+1, where 1≤j≤63; l indicates that there are l AC coefficients in total.
[0023] S4-3, Collect a i,j-l ≠0 and a i,j The set of AC coefficients ≠ 0 is used to obtain the complete set of blocks. This complete set is then scrambled and encrypted; where i is the i-th block; a i,j This represents the AC coefficient value of the j-th frequency in the i-th block; a i,j-l This represents the AC coefficient value of the jl-th frequency of the i-th block;
[0024] S4-4, Collect a i,j-l ≠0 and j>p i , {a i,j-l+1 ,...,a i,j The coefficient set of} is obtained and the final set is scrambled and encrypted, where p i This represents the position of the last non-0 AC coefficient in the i-th block;
[0025] S4-5. Repeat steps S4-1 to S4-4, traversing all frequencies of AC coefficients and the set L of AC coefficient group lengths to obtain the AC coefficient group scrambling encryption. in, t represents the maximum run value of the non-zero AC coefficients among the AC coefficients at the j-th frequency. j The range generated for key K is 2 to Random numbers.
[0026] Furthermore, step S5 is implemented as follows:
[0027] S5-1, Extraction The frequency position of the last non-0AC coefficient in each block;
[0028] S5-2, Sort the images to obtain image features F.
[0029] Furthermore, step S6 is implemented as follows:
[0030] S6-1. Using F as the input to the hash function, generate a 512-bit hash value;
[0031] S6-2. Combine the 512-bit hash value with K to construct the adaptive key KA.
[0032] Furthermore, step S7 is implemented as follows:
[0033] S7-1. Use the adaptive key KA to generate a block scrambling sequence;
[0034] S7-2, For those containing only the AC coefficient Perform block scrambling and obtain the encrypted AC coefficients.
[0035] Furthermore, step S8 is implemented as follows:
[0036] S8-1. Obtain the minimum DC coefficient β related to the quality factor based on the quantization table of the JPEG image to be encrypted. min and the maximum value β max ,
[0037] S8-2, using |β min |Adding the DC prediction error value yields a non-negative DC prediction error value;
[0038] S8-3, Divide the non-negative DC prediction error value into β max -β min +1 group, each group contains One element; n represents the number of blocks; This indicates a round-down operation;
[0039] S8-4. Generating random number γ using adaptive key KA g ∈[1,β max -β min ];in,
[0040] g represents the group number of the DC group, and mod represents the modulo operation;
[0041] S8-5. Add the same random number γ to each group of DC prediction error values. g This keeps the DC difference within the block constant, resulting in a DC prediction error value with added random numbers.
[0042] S8-6. According to the formula:
[0043]
[0044] Obtain the DC coefficient value after performing modulo operation encryption on the DC prediction error value with added random numbers. Where, ξ i This represents the DC prediction error value of the i-th block.
[0045] The beneficial effects of this invention are as follows:
[0046] 1. This invention achieves a JPEG image encryption scheme without overflow processing by performing modulo operation on the prediction error of the positive DC coefficient and classifying and scrambling the AC coefficient group for encryption; it avoids the problem that the amount of overflow processing data is less than the image embedding capacity, which leads to the inability to decrypt the image correctly, and improves the universality of encryption and decryption.
[0047] 2. This invention improves the ability of encrypted images to resist statistical model attacks by increasing the feature value change rate; and improves the feature value change rate by classifying and scrambling the AC coefficient group containing complete AC coefficients. Attached Figure Description
[0048] Figure 1 This is a flowchart of the present invention.
[0049] Figure 2 Test image for Baboon;
[0050] Figure 3 For Couple test images;
[0051] Figure 4 For Airplane test images;
[0052] Figure 5 Test image for Lena;
[0053] Figure 6 Baboon encrypted images with a quality factor of 85;
[0054] Figure 7 Encrypt a Couple image with a quality factor of 85;
[0055] Figure 8 Encrypted images of an Airplane with a quality factor of 85;
[0056] Figure 9 A Lena encrypted image with a quality factor of 85;
[0057] Figure 10 A comparison chart of file growth for Baboon images encrypted using the present invention and existing methods;
[0058] Figure 11A comparison chart of file growth for Couple images encrypted using the present invention and existing methods;
[0059] Figure 12 Comparison chart of file growth for Airplane images encrypted using the present invention and existing methods;
[0060] Figure 13 A comparison chart of file growth for Lena images encrypted using the present invention and existing methods;
[0061] Figure 14 The rate of change of NCC for the test image with a quality factor of 85 before block scrambling;
[0062] Figure 15 The PLZ change rate of the test image with a quality factor of 85 before block scrambling;
[0063] Figure 16 The rate of change of EAC for the test image with a quality factor of 85 before block scrambling. Detailed Implementation
[0064] The specific embodiments of the present invention are described below to enable those skilled in the art to understand the present invention. However, it should be understood that the present invention is not limited to the scope of the specific embodiments. For those skilled in the art, various changes are obvious as long as they are within the spirit and scope of the present invention as defined and determined by the appended claims. All inventions utilizing the concept of the present invention are protected.
[0065] like Figure 1 As shown, a JPEG image encryption method based on coefficient block encryption includes the following steps:
[0066] S1. Read the quantization table, Huffman coding table, and entropy-coded stream of DCT coefficients of the JPEG image to be encrypted;
[0067] S2. Parse the entropy coding stream of the DCT coefficients according to the Huffman coding table to obtain the original DC coefficient differential entropy coding and AC coefficient entropy coding of all blocks.
[0068] S3. Obtain the original DC coefficients based on the differential entropy encoding of the original DC coefficients, and predict the DC coefficients to obtain the DC prediction error value;
[0069] S4. Obtain and use the initial key K to scramble and encrypt the AC coefficient groups containing the complete AC coefficient entropy encoding, and obtain the encrypted AC coefficients.
[0070] S5. Extract image features F based on the AC coefficient group scrambling encryption result containing complete AC coefficient entropy encoding;
[0071] S6. Generate an adaptive key KA related to the image content using the initial key K and image features F;
[0072] S7. Using the adaptive key KA, for Perform block scrambling encryption to obtain the encrypted AC coefficient.
[0073] S8. Using the quantization table of the JPEG image to be encrypted and the adaptive key KA, positiveize the DC prediction error and perform modulo encryption to obtain the encrypted DC coefficients.
[0074] S9, DC coefficient for encryption and AC coefficient Entropy encoding is performed to obtain an encrypted image.
[0075] The implementation method of step S3 is as follows:
[0076] S3-1. Obtain the original DC coefficients based on the differential entropy encoding of the original DC coefficients;
[0077] S3-2. Decode all blocks of the JPEG image to be encrypted into pixels;
[0078] S3-3. Use the 8 pixels adjacent to the target block in the block to the left and the block above the current block to predict the DC coefficient value.
[0079] S3-4. Subtract the predicted DC coefficient value from the original DC coefficient value to obtain the DC prediction error value.
[0080] The specific implementation method of step S4 is as follows:
[0081] S4-1. Obtain j AC coefficients of different frequencies based on AC coefficient entropy encoding;
[0082] S4-2. Obtain the AC coefficient set based on the AC coefficients, where the AC coefficient set is {a i,j-l+1 ,...,a i,j} represents the set of AC coefficients with an endpoint frequency of j and an initial frequency of j-l+1, where 1≤j≤63; l indicates that there are l AC coefficients in total.
[0083] S4-3, Collect a i,j-l ≠0 and a i,j The set of AC coefficients ≠ 0 is used to obtain the complete set of blocks. This complete set is then scrambled and encrypted; where i is the i-th block; a i,j This represents the AC coefficient value of the j-th frequency in the i-th block; a i,j-l This represents the AC coefficient value of the jl-th frequency of the i-th block;
[0084] S4-4, Collect a i,j-l ≠0 and j>p i , {a i,j-l+1 ,...,a i,j The coefficient set of} is obtained and the final set is scrambled and encrypted, where p i This represents the position of the last non-zero AC coefficient in the i-th block;
[0085] S4-5. Repeat steps S4-1 to S4-4, traversing all frequencies of AC coefficients and the set L of AC coefficient group lengths to obtain the AC coefficient group scrambling encryption. in, t represents the maximum run value of the non-zero AC coefficients among the AC coefficients at the j-th frequency. j The range generated for key K is 2 to Random numbers.
[0086] The implementation method of step S5 is as follows:
[0087] S5-1, Extraction The frequency position of the last non-0AC coefficient in each block;
[0088] S5-2, Sort the images to obtain image features F.
[0089] The implementation method of step S6 is as follows:
[0090] S6-1. Using F as the input to the hash function, generate a 512-bit hash value;
[0091] S6-2. Combine the 512-bit hash value with K to construct the adaptive key KA.
[0092] The implementation method for step S7 is as follows:
[0093] S7-1. Use the adaptive key KA to generate a block scrambling sequence;
[0094] S7-2, For those containing only the AC coefficient Perform block scrambling and obtain the encrypted AC coefficients.
[0095] The implementation method of step S8 is as follows:
[0096] S8-1. Obtain the minimum DC coefficient β related to the quality factor based on the quantization table of the JPEG image to be encrypted. min and the maximum value β max ,
[0097] S8-2, using |β min|Adding the DC prediction error value yields a non-negative DC prediction error value;
[0098] S8-3, Divide the non-negative DC prediction error value into β max -β min +1 group, each group contains One element; n represents the number of blocks; This indicates a round-down operation;
[0099] S8-4. Generating random number γ using adaptive key KA g ∈[1,β max -β min ];in,
[0100] g represents the group number of the DC group, and mod represents the modulo operation;
[0101] S8-5. Add the same random number γ to each group of DC prediction error values. g This keeps the DC difference within the block constant, resulting in a DC prediction error value with added random numbers.
[0102] S8-6. According to the formula:
[0103]
[0104] Obtain the DC coefficient value after performing modulo operation encryption on the DC prediction error value with added random numbers. Where, ξ i This represents the DC prediction error value of the i-th block.
[0105] In one embodiment of the present invention, the experimental platform was an Intel i5-6200U 2.30GHz CPU, 8GB (7.9GB) RAM, and Matlab R2018b with a 64-bit operating system; four images were selected as test images, all of which were 512×512 grayscale images; as shown Figure 2 , Figure 3 , Figure 4 and Figure 5 As shown; Figure 2 Test image for Baboon; Figure 3 For Couple test images; Figure 4 For Airplane test images; Figure 5 The image shown is a test image for Lena. The encryption effect of this invention on a test image with a quality factor of 85 is as follows: Figures 6 to 9 As shown, Figure 6 Baboon encrypted images with a quality factor of 85; Figure 7 Encrypt a Couple image with a quality factor of 85; Figure 8Encrypted images of an Airplane with a quality factor of 85; Figure 9 A Lena encrypted image with a quality factor of 85;
[0106] Comparison of file incrementality and general applicability:
[0107] The file increment of this invention was experimentally compared with the methods proposed by He et al. and Qin et al., and the results are as follows: Figure 10 , Figure 11 , Figure 12 , Figure 13 As shown; Figures 10 to 13 The file size differences between the encrypted and original images for four test images with quality factors ranging from 65 to 95 are presented. It can be seen that He et al.'s file size change is relatively small, while Qin et al.'s and the present invention's algorithms show larger changes. Since He et al.'s encryption did not change the image encoding, their file size change mainly comes from byte padding. Qin et al.'s and the present invention's AC encryption algorithm do not produce file size changes; their file size changes mainly come from DC encryption. In DC encryption, two factors affect file size: DC coefficient prediction and the selection of different random numbers between adjacent groups. The former reduces the DC coefficient value, thus reducing file size, while the latter increases the difference in DC coefficients between adjacent groups, leading to file size increase. For general images, the former has a greater impact than the latter, thus reducing the overall file size. However, for texture images, the former has a lesser impact than the latter, resulting in increased file size. Compared to Qin et al., the encryption algorithm in this paper is applicable to all images, while Qin et al.'s algorithm, due to limitations in embedding capacity, failed to decrypt some images correctly, such as the Lena, Couple, and Airplane images with a quality factor of 65. In summary, this invention can achieve correct encryption and decryption of any image while ensuring that the amount of file changes is close to that of Qin et al., thus having higher versatility.
[0108] Security Analysis:
[0109] The rate of change of features before block scrambling encryption is statistically analyzed using the methods proposed by He, Qin, and this invention, such as... Figure 14 , Figure 15 and Figure 16 As shown. It can be seen that He et al., Qin et al., and the present invention all modified the EAC, with the present invention showing the highest modification rate. The coefficient group classification encryption of the present invention has a higher degree of scrambling compared to the same-run AC coefficient scrambling of He et al. and the local AC coefficient global scrambling of Qin et al. Compared to Qin et al., the modification rate of the EAC of the present invention increased by 5.59%. For NCC and PLZ, He et al. did not change them. Figure 14 , Figure 15 and Figure 16It can be seen that the present invention can change NCC and PLZ to a greater extent. For NCC, Qin et al. only changed NCC by overflow processing. However, due to the limitation of embedding capacity and the influence of quality factor, the number of overflow blocks is not large. Therefore, the NCC change rate of Qin et al. is low. Compared with Qin et al., the NCC change rate of the present invention increased by 93.25%. The main reason is that the number of non-0 AC coefficients contained in the complete group and the end group in the proposed algorithm is different. For PLZ features, Qin et al. changed PLZ to a certain extent by scrambling AC coefficients containing different runs. However, most of the AC coefficients used by Qin et al. for scrambling are concentrated in low frequency, and their runs are mostly 0. Therefore, the PLZ change rate of Qin et al.
[25] is low. Compared with Qin et al., the PLZ change rate of the present invention increased by 16.20%. This is mainly because the present invention scrambled the end group, and the PLZ change rate gradually increased after multiple iterations. Wherein, NCC represents the number of non-0 AC coefficients, PLZ represents the position of the last non-0 AC coefficient in the block, and EAC represents the energy of the AC coefficient in the block.
[0110] This invention requires no overflow handling, thus avoiding the problem that the image cannot be decrypted correctly when the amount of overflow information is greater than the embedding capacity, improving the universality of encryption and decryption. By classifying and scrambling the AC coefficient group containing complete AC coefficients for encryption, the statistical characteristics of NCC, PLZ and EAC are changed, improving the ability to resist statistical model attacks.
Claims
1. A method for encrypting JPEG image based on coefficient grouping, characterized in that, The method comprises the following steps: S1, reading the quantization table, the Huffman coding table and the entropy coding stream of DCT coefficients of the JPEG image to be encrypted; S2, parsing the entropy coding stream of DCT coefficients according to the Huffman coding table to obtain the original DC coefficient differential entropy coding and the AC coefficient entropy coding of all blocks; S3, obtaining the original DC coefficient according to the original DC coefficient differential entropy coding, and predicting the DC coefficient to obtain the DC prediction error value; S4, obtain and use the initial key K, encrypt the AC coefficient group containing the complete AC coefficient entropy coding by permutation encryption and obtain the encrypted AC coefficient ; The method comprises the following steps: S4-1, obtaining according to AC coefficient entropy coding j AC coefficients of different frequencies; S4-2, obtaining an AC coefficient set according to the AC coefficient, wherein the AC coefficient set is , representing a set of AC coefficients with an end frequency of j , and a start frequency of , ; l representing that there are l AC coefficients in common; S4-3, collecting and The AC coefficient array of the complete group set is encrypted by shuffling; wherein, i is the i block; represents the AC coefficient value of the i block of the j frequency; represents the AC coefficient value of the i block of the j-l frequency; S4-4, collect and , the coefficient group and get the end group set, and perform shuffling and encryption thereon, wherein, is the position of the last non-0 AC coefficient in the i th block. S4-5, repeating steps S4-1 to S4-4, traversing all the frequency AC coefficients and AC coefficient group length set L, to obtain AC coefficient group permutation encryption ; wherein, , is the maximum run value of non-0 AC coefficients in the AC coefficients of the j th frequency, is a random number generated by the key K, ranging from 2 to . S5, extracting the image feature F based on the AC group grouping scrambling encryption result containing the complete AC coefficient entropy coding; S6, generating the adaptive key KA related to the image content by using the initial key K and the image feature F; S7, using the adaptive key KA, the AC coefficients are encrypted by block permutation encryption to obtain encrypted AC coefficients ; S8, using the quantization table of the JPEG image to be encrypted, the adaptive key KA, positive the DC prediction error and encrypt by modulo operation, get the encrypted DC coefficient ; S9, encrypting DC coefficients and AC coefficients performing entropy encoding to obtain an encrypted image.
2. The JPEG image encryption method based on coefficient grouping encryption according to claim 1, characterized in that, The implementation of step S3 is as follows: S3-1, obtaining the original DC coefficient according to the original DC coefficient differential entropy coding; S3-2, decoding all blocks of the JPEG image to be encrypted into pixels; S3-3, predicting the DC coefficient by using the 8 adjacent pixels in the left block and the upper block of the target block to obtain the predicted DC coefficient value; S3-4, subtracting the predicted DC coefficient value from the original DC coefficient value to obtain the DC prediction error value.
3. The JPEG image encryption method based on coefficient grouping encryption according to claim 1, characterized in that, The implementation of step S5 is as follows: S5-1, extracting the frequency position of the last non-zero AC coefficient of each block; S5-2, sorting the AC coefficient entropy coding to obtain the image feature F.
4. The JPEG image encryption method based on coefficient grouping encryption according to claim 3, characterized in that, The implementation of step S6 is as follows: S6-1, taking F as the input of the hash function to generate a 512-bit hash value; S6-2, combining the 512-bit hash value and K to construct the adaptive key KA.
5. The JPEG image encryption method based on coefficient grouping encryption according to claim 4, characterized in that, The implementation of step S7 is as follows: S7-1, generating the block scrambling sequence by using the adaptive key KA; S7-2, for AC coefficients only performing a block scrambling operation and obtaining encrypted AC coefficients .
6. The JPEG image encryption method based on coefficient grouping encryption according to claim 5, characterized in that, The implementation of step S8 is as follows: S8-1. Obtain the minimum value of DC coefficient related to the quality factor from the quantization table of the JPEG image to be encrypted and the maximum value , S8-2, with adding the DC prediction error value to obtain a non-negative DC prediction error value; S8-3, dividing the non-negative DC prediction error values into groups, each group containing elements; n denotes the number of blocks; denotes a floor operation; S8-4, generating a random number using an adaptive key KA ; wherein, ; g denotes a group number of the DC packet, mod denotes a modulo operation; S8-5, add the same random number to each group of DC prediction error values so that the intra-block DC difference remains unchanged, obtaining the DC prediction error values added with the random number; S8-6, according to the formula: DC coefficient values obtained by performing modulo operation encryption on DC prediction error values to which random numbers are added ; wherein denotes the DC prediction error value of the i th block.