Disclosure of Invention
The invention aims to provide a method for realizing image encryption by adopting nonlinear low-pass filtering, and further solves the problems of difficult expansion and low-pass transformation distortion in the traditional image encryption and decryption algorithm to a certain extent.
Step S10, reading the file to be encrypted by a computer, storing the file as a matrix array, and then performing data conversion processing;
step S20, performing extensible first low-pass filtering transformation on the data to obtain a first low-pass filtering matrix, and taking a first low-pass filtering parameter as a first secret key;
step S30, carrying out secondary low-pass filtering transformation on the primary low-pass filtering matrix data to obtain a secondary low-pass filtering matrix, and taking secondary low-pass filtering parameters as a second key;
step S40, carrying out nonlinear symmetric transformation on the quadratic low-pass filter matrix to obtain nonlinear symmetric matrix data, and taking nonlinear symmetric transformation parameters as a third key;
step S50, image data conversion is carried out on the nonlinear symmetric matrix data and then the nonlinear symmetric matrix data is stored as an image file, the encryption process is completed, and the encrypted data file is sent out;
step S60, receiving the sending file at the receiving end and storing the file as matrix data, and carrying out data preprocessing to obtain a receiving end data matrix;
step S70, according to the third key, carrying out nonlinear symmetric inverse transformation on the receiving end data matrix to obtain nonlinear symmetric inverse transformation matrix data;
step S80, according to the second key, carrying out secondary low-pass filtering inverse transformation on the nonlinear symmetric inverse transformation matrix to obtain an inverse secondary low-pass filtering matrix;
step S90, according to the first key, the inverse quadratic low-pass filtering matrix is inversely transformed by the first low-pass filtering to obtain an inverse matrix of the first low-pass filtering;
and S100, performing data conversion aiming at the first low-pass filtering inverse matrix, storing the converted data as picture data, obtaining a decrypted file, and finishing the decryption process.
In an exemplary embodiment of the present invention, reading a file to be encrypted by using a computer, storing the file as a matrix array, and then performing data conversion processing includes: firstly, selecting a gray picture file to be encrypted, and naming the gray picture file as rain. Then stored as data matrix A1Then, the dimension is calculated and recorded as m rows and n columns. Then, for the matrix A1Carrying out data recombination to obtain a row matrix A with 1 row m × n columns2. Finally, for A2Simple normalization pretreatment is carried out to obtain a normalization matrix A of matrix element numbers in an interval (0,1)3。
In an exemplary embodiment of the present invention, performing an extensible first low-pass filtering transformation on the data to obtain a first low-pass filtering matrix comprises:
wherein T is
1,T
2,T
3,T
4The first key is used to inform the receiving party that the first low-pass filtering transformation parameters are all positive constant value parameters, which are selected in detail in the embodiments described later. T is
0The discrete time constants are chosen in detail as will be described later in the examples. A. the
4The dimension of the obtained first low-pass filter matrix is 1 row m x n column. And A is
4(i) I is more than or equal to 1 and less than or equal to mn. The subsequent matrix definitions are the same and are not repeated.
Is a matrix A
3Is determined by the velocity vector of (a),
is a matrix A
4Velocity vector of A
3The input matrix is an input matrix of the first low-pass filtering transformation, namely a normalized row matrix obtained after data conversion processing is carried out on the file to be encrypted.
In an exemplary embodiment of the present invention, performing a second low-pass filtering transformation on the first low-pass filtering matrix data to obtain a second low-pass filtering matrix includes:
wherein W
1,W
2,W
3,W
4The second key is used to inform the receiver that the second low-pass filter transformation parameters are all positive constant value parameters, which are selected in detail in the embodiments described later. T is
0Are discrete time constants.
Is a matrix A
4The velocity vector whose value does not need to be recalculated, has been defined or calculated previously.
A
5The dimension of the quadratic low-pass filter matrix is 1 row m x n column. And A is
5(i) I is more than or equal to 1 and less than or equal to mn.
Is a matrix A
5Velocity vector of A
4The input matrix of the second low-pass filtering transformation is the first low-pass filtering matrix.
In an exemplary embodiment of the present invention, performing a non-linear symmetric transformation on the quadratic low-pass filter matrix to obtain non-linear symmetric matrix data includes:
when in use
When the temperature of the water is higher than the set temperature,
when in use
When the temperature of the water is higher than the set temperature,
wherein F1,F2,F3,F4The non-linear symmetric transformation parameter is a constant value, which is informed to the receiver as a third key. A. the5Is a quadratic low-pass filter matrix, A6The obtained nonlinear symmetric matrix is obtained.
In an exemplary embodiment of the present invention, converting the nonlinear symmetric matrix data into image data and then storing the image data as an image file includes:
imax=max(A6);imin=min(A6);
If imax=imin>0;A7(i)=1;
If imax=imin≤0;A7(i)=0;
Wherein A is6For said non-linear symmetric matrix data, A7For normalizing the transformation matrix, where max (A)6) Representation pair matrix A6All elements of (2) are maximized and are denoted as imax。min(A6) Representation pair matrix A6All elements of (2) are minimized and are denoted as imin。
Then to A7Performing data recombination, converting the data into an m-row-n-column matrix A from a 1-row-m-n-column matrix8And stored as an image data file, which is recorded as rain1. png. And the image encryption process is finished, and the encrypted image file rain1.png is sent to the remote receiving end.
In an exemplary embodiment of the present invention, receiving a transmission file at a receiving end and storing the transmission file as matrix data, and performing data preprocessing to obtain a receiving end data matrix includes: firstly, the sent encrypted image file is received at a remote receiving end and stored as rain2. png. Secondly, after reading the image file by adopting a computer, storing the data into a matrix A with m rows and n columns9. Then the matrix A is formed9Carrying out data recombination to obtain a matrix A with 1 row m x n10. Finally, according to iminAnd imaxTo A10Inverse normalized transformation is carried out to obtain a receiving end data matrix A11The inverse normalized transformation process is as follows:
if imax≠imin;A11(i)=imin+A10(i)(imax-imin);
If imax=imin>0;A11(i)=imax;
If imax=imin≤0;A11(i)=imin。
In an exemplary embodiment of the present invention, performing a nonlinear symmetric inverse transform on a receiving-end data matrix to obtain nonlinear symmetric inverse transform matrix data includes:
when in use
When the temperature of the water is higher than the set temperature,
when in use
When the temperature of the water is higher than the set temperature,
wherein F1,F2,F3,F4Is said third key, A11For the receiving end data matrix, A12I.e. the resulting nonlinear symmetric inverse transform matrix data.
In an exemplary embodiment of the invention, performing an inverse quadratic low-pass filtering on the inverse nonlinear symmetric transform matrix to obtain an inverse quadratic low-pass filtering matrix comprises:
wherein W
1,W
2,W
3,W
4Is a second key parameter, T
0With a discrete time constant, A
12For the non-linear symmetric inverse transformation of the matrix data,
is a matrix A
12Is determined by the velocity vector of (a),
is a matrix A
13Velocity vector of A
13The dimension of the obtained inverse quadratic low pass filter matrix is 1 row m x n column.
In an exemplary embodiment of the invention, performing a first inverse low-pass filtering on the inverse quadratic low-pass filtering matrix, and obtaining the first inverse low-pass filtering matrix comprises:
wherein
Without recalculation, the last step value, T, can be used
1,T
2,T
3,T
4Is a first key parameter, T
0With a discrete time constant, A
13In order to be an inverse quadratic low pass filter matrix,
is a matrix A
14Velocity vector of A
14The first inverse low-pass filter matrix is finally obtained, and the dimension of the first inverse low-pass filter matrix is 1 row m x n column.
In an exemplary embodiment of the present invention, performing data conversion on the first low-pass filtered inverse matrix, and storing the converted data as picture data, to obtain a decrypted file includes: according to the first low-pass filtering inverse matrix A14Converting into image matrix format, i.e. converting from 1 row m × n column to m rows n columns, and recording the obtained matrix as A15. Then A is mixed15Stored as an image file, noted rain2. png. Finally, the decrypted file is obtained.
Advantageous effects
The method for realizing image encryption by adopting nonlinear low-pass filtering has the advantages of three, firstly, the method adopts a novel low-pass filtering transformation mode, can realize the consistency of encryption and decryption modes, ensures that the decryption process has no distortion, and avoids the problem of image distortion caused by differential realization in decryption and reduction of the traditional low-pass filtering transformation. And secondly, a novel nonlinear symmetrical transformation mode is adopted, so that the encryption and decryption are very convenient, the free transformation of all the number domains can be realized, the decryption is more difficult, and in the decryption process, the complete restoration of the image can be realized without distortion due to seamless butt joint. And thirdly, the mode of combining the low-pass filtering and the nonlinear symmetric transformation can be expanded infinitely to form a multi-layer encryption and decryption measure, and the security of encrypted image data is improved through a plurality of layers of keys. Therefore, the method provided by the invention has high engineering application value and great innovation.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to provide a thorough understanding of embodiments of the invention. One skilled in the relevant art will recognize, however, that the invention may be practiced without one or more of the specific details, or with other methods, components, devices, steps, and so forth. In other instances, well-known technical solutions have not been shown or described in detail to avoid obscuring aspects of the invention.
The invention provides a method for realizing image encryption by adopting nonlinear low-pass filtering, which forms multilayer encryption by combining multilayer low-pass filtering transformation and multilayer nonlinear symmetrical transformation to protect an encrypted image. And meanwhile, a multi-layer key is formed through parameters in a conversion mode, so that correct parameters are provided for image decryption. It should be noted that, in the embodiment of the present invention, only two layers of low-pass filtering and one layer of nonlinear symmetric transformation are used for description, but actually, the low-pass filtering method and the nonlinear symmetric transformation method provided by the present invention can be flexibly combined many times, as long as the computer memory allows, hundreds of layers of encryption can be implemented, and meanwhile, it can be ensured that the decryption process is basically distortion-free. Therefore, the method has very flexible and free expansibility and high safety. Particularly, the low-pass filtering form is adopted, so that the problem of differential distortion generated in decryption engineering by the traditional low-pass filtering is avoided, and the traditional low-pass filtering is difficult to carry out multilayer expansion application.
The following further explains and explains a method for realizing image encryption by using nonlinear low-pass filtering according to the present invention with reference to the drawings. Referring to fig. 1, the method for implementing image encryption by using nonlinear low-pass filtering may include the following steps:
step S10, reading the file to be encrypted by a computer, storing the file as a matrix array, and then performing data conversion processing;
specifically, a file to be encrypted is first selected, named rain. In the case of a color picture, it is first converted to a gray picture.
Secondly, reading the gray picture data, storing the gray picture data as a data matrix, and recording the data matrix as A1Then, the dimension is obtained, which is a two-dimensional matrix and is recorded as m rows and n columns.
Then, for the matrix A1Performing data reorganization to obtain a row matrix, and recording the row matrix as A2Which is a one-dimensional matrix with 1 row m x n columns.
Finally, for A2Performing simple normalization pretreatment to obtain a normalization matrix, and recording the normalization matrix as A3. The normalization process is to ensure A3The middle matrix element number is within the interval (0, 1).
Step S20, performing extensible first low-pass filtering transformation on the data to obtain a first low-pass filtering matrix, and taking a first low-pass filtering parameter as a first secret key;
specifically, first, the first low-pass filter transformation parameter T is set1,T2,T3,T4The parameter is a positive constant value parameter, which is selected in detail in the following embodiment and the above four parameters are used as the first key to inform the receiving party.
Secondly, a discrete time constant T is set0And sets the initial value of the first low-pass filter matrix. Namely is provided withThe first low-pass filter matrix obtained finally is A4The dimension is 1 row m x n column. And A is4(i) I is more than or equal to 1 and less than or equal to mn. The subsequent matrix definitions are the same and are not repeated. Setting an initial value A of a matrix4(1)=A3(1)。
Thirdly, calculate the matrix A
3Velocity vector of (2) is recorded as
It is calculated as follows:
then, a matrix A is calculated
4Velocity vector of (2) is recorded as
It is calculated as follows:
finally, according to the velocity vector
Calculating a first low-pass filter matrix A
4The element values of (a) are as follows:
step S30, carrying out secondary low-pass filtering transformation on the primary low-pass filtering matrix data to obtain a secondary low-pass filtering matrix, and taking secondary low-pass filtering parameters as a second key;
specifically, firstly, a quadratic low-pass filter transformation parameter W is set1,W2,W3,W4The parameters are positive constant values, which are detailed in the following embodiments and are reported to the receiver as the second key.
Secondly, a discrete time constant T is set0And sets the initial value of the quadratic low-pass filter matrix. Namely, the finally obtained quadratic low-pass filter matrix is set as A5The dimension is 1 row m x n column. Setting an initial value A of a matrix5(1)=A4(1)。
Then, a matrix A is calculated
5Velocity vector of (2) is recorded as
It is calculated as follows:
wherein the matrix A
4Velocity vector of
The last step value can be used without recalculation.
Finally, according to the velocity vector
Calculating a quadratic low-pass filter matrix A
5The element values of (a) are as follows:
although the above-described low-pass filtering conversion is performed only twice, it is actually possible to perform a larger number of low-pass filtering conversions more conveniently and to realize a plurality of encryptions. And the transformation has no singular point, and is very convenient for multiple times of expansion.
Step S40, carrying out nonlinear symmetric transformation on the quadratic low-pass filter matrix to obtain nonlinear symmetric matrix data, and taking nonlinear symmetric transformation parameters as a third key;
specifically, first, a nonlinear symmetric transformation parameter F is set1,F2,F3,F4It is a common value, and its detailed design is described laterThe case is implemented and informed to the recipient as the third key.
Secondly, aiming at the quadratic low-pass filtering matrix A5Then, nonlinear symmetric transformation is performed to obtain a nonlinear symmetric matrix, which is denoted as A6The transformation relationship among the elements is as follows:
when in use
When the temperature of the water is higher than the set temperature,
when in use
When the temperature of the water is higher than the set temperature,
step S50, image data conversion is carried out on the nonlinear symmetric matrix data and then the nonlinear symmetric matrix data is stored as an image file, the encryption process is completed, and the encrypted data file is sent out;
specifically, the nonlinear symmetric matrix a is first obtained6The data is normalized and transformed to obtain a normalized matrix, which is recorded as A7The transformation is as follows:
imax=max(A6);imin=min(A6);
If imax=imin>0;A7(i)=1;
If imax=imin≤0;A7(i)=0;
Wherein max (A)6) Representation pair matrix A6All elements of (2) are maximized and are denoted as imax。min(A6) Representation pair matrix A6All elements of (2) are minimizedIs recorded as imin。
Secondly, for A7Performing data recombination, converting the data from a matrix with 1 row m × n columns into a matrix with m rows and n columns, and recording the matrix as A8。
Finally, converting the obtained A8Stored as an image data file, and recorded as rain1. png. And the image encryption process is finished, and the encrypted image file rain1.png is sent to the remote receiving end.
Step S60, receiving the sending file at the receiving end and storing the file as matrix data, and carrying out data preprocessing to obtain a receiving end data matrix;
specifically, the sent encrypted image file is received at the remote receiving end and stored as rain2. png. Secondly, after reading the image file by adopting a computer, storing the data as a matrix, and recording the matrix as A9. The matrix is m rows and n columns.
Then the matrix A is formed9Recombining data, converting into one-dimensional row vector to obtain 1 row m × n column matrix, and recording as A10. Finally, according to iminAnd imaxTo A10Inverse normalized transformation is carried out to obtain a receiving end data matrix A11The inverse normalized transformation process is as follows:
if imax≠imin;A11(i)=imin+A10(i)(imax-imin);
If imax=imin>0;A11(i)=imax;
If imax=imin≤0;A11(i)=imin。
Step S70, according to the third key, carrying out nonlinear symmetric inverse transformation on the receiving end data matrix to obtain nonlinear symmetric inverse transformation matrix data;
in particular, according to said third key F1,F2,F3,F4To the receiving end data matrix A11Performing nonlinear symmetric inverse transformation to obtain nonlinear symmetric inverse transformation matrix data denoted by A12Element conversion between themThe method comprises the following steps:
when in use
When the temperature of the water is higher than the set temperature,
when in use
When the temperature of the water is higher than the set temperature,
step S80, according to the second key, carrying out secondary low-pass filtering inverse transformation on the nonlinear symmetric inverse transformation matrix to obtain an inverse secondary low-pass filtering matrix;
specifically, according to the second key parameter W1,W2,W3,W4And a discrete time constant T0And setting the initial value of the quadratic low-pass filter inverse matrix. Namely, the finally obtained inverse quadratic low pass filter matrix is set as A13The dimension is 1 row m x n column. Setting an initial value A of a matrix13(1)=A12(1)。
Thirdly, calculate the matrix A
12Velocity vector of (2) is recorded as
It is calculated as follows:
then, a matrix A is calculated
13Velocity vector of (2) is recorded as
It is calculated as follows:
finally, according to the velocity vector
Calculating an inverse quadratic low pass filter matrix A
13The element values of (a) are as follows:
step S90, according to the first key, the inverse quadratic low-pass filtering matrix is inversely transformed by the first low-pass filtering to obtain an inverse matrix of the first low-pass filtering;
specifically, according to the first key parameter T1,T2,T3,T4And a discrete time constant T0And setting an initial value of the first low-pass filtering inverse matrix. Namely, the finally obtained first low-pass filter inverse matrix is set as A14The dimension is 1 row m x n column. Setting an initial value A of a matrix14(1)=A13(1)。
Then, a matrix A is calculated
14Velocity vector of (2) is recorded as
It is calculated as follows:
wherein the velocity vector
The last step value can be used without recalculation.
Finally, according to the velocity vector
Calculating a first low-pass filter inverse matrix A
14The element values of (a) are as follows:
and S100, performing data conversion aiming at the first low-pass filtering inverse matrix, storing the converted data as picture data, obtaining a decrypted file, and finishing the decryption process.
Specifically, according to the first low-pass filtering inverse matrix A14Converting into image matrix format, i.e. converting from 1 row m × n column to m rows n columns, and recording the obtained matrix as A15. Then A is mixed15Stored as an image file, noted rain2. png. Finally, the decrypted file is obtained. It can be seen by comparison that there is almost no difference from the original file, the distortion degree is very small, but if the decryption parameter is not correct, the image information cannot be identified.
Case implementation and computer processing result analysis
In step S10, the image file is selected as a screenshot of a segment of text. Since it is a color image, it is converted into a black-and-white image, and then it is shown in fig. 2. It contains m 159 rows and n 698 columns.
In step S20, the first low-pass filter transformation parameter T is set1=0.01,T2=1,T3=0.02,T4=1,T0=0.001;
In step S30, a quadratic low-pass filtering conversion parameter W is set1=0.03,W2=2,W3=0.05,W4=3;
In step S40, a nonlinear-symmetric transformation parameter F is set1=1,F2=100,F3=1,F4=-100;
The encrypted data is stored as an encrypted image and transmitted in step S50, as shown in fig. 3.
In steps S60 and S100, the operation may be performed as described in the embodiment.
In steps S70, S80, and S90, the picture is decrypted by using the accurate first key, second key, and third key parameters, and the effect after decryption is shown in fig. 4.
When the first key takes the decryption parameter T1=0.01,T2=3,T3=0.02,T4When 1, the decryption effect is as shown in fig. 5.
When the first key takes the decryption parameter T1=0.01,T2=3,T3=3,T4When 1, the decryption effect is as shown in fig. 6.
When the third key takes the decryption parameter F1=1,F2=100,F3=1,F4When-5, the decryption effect is as shown in fig. 7.
When the third key takes the decryption parameter F1=1,F2=100,F3=50,F4The decryption effect is shown in fig. 8 when-100.
It can be seen from the above cases that the encryption method provided by the present invention, when the picture is intercepted by the other party, the picture is black, as shown in fig. 3, the text information is completely hidden. Under the protection of three keys, the error of any one key will bring about bad decryption effect and distortion of graphics. Of course, the key parameters are somewhat less distorted, e.g., F in the third key parameter4However, some key parameters have a great influence on the decryption effect. Therefore, through three-layer encryption, the security of the picture is greatly improved. Particularly, the nonlinear low-pass filtering encryption method provided by the invention has the advantages that each key is very convenient to expand, the decryption and encryption modes are similar, the operation is convenient and simple, and the nonlinear low-pass filtering encryption method can be expanded into a multilayer encryption mode such as four layers and five layers if needed. Therefore, the invention has high engineering application value.
Other embodiments of the invention will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the invention and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the invention being indicated by the following claims.