Data encryption and recovery method and device based on XOR, equipment and medium
By optimizing the XOR algorithm and image encryption method, combined with the embedding technology of out-of-order ciphertext and random images, the crackable and irreversible problems of the data encryption and recovery process in the prior art are solved, and high reliability and dual protection data encryption and recovery effects are achieved.
Patent Information
- Application Number
- CN202510208082.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-25
- Publication Date
- 2025-03-28
AI Technical Summary
The prior art has crackable and irreversible problems in the data encryption and recovery process, and it is difficult to effectively ensure the security and recoverability of data.
The XOR-based data encryption and recovery method is adopted, and the plaintext data is encrypted by optimizing the XOR algorithm, combined with the least significant bit, and the out-of-order ciphertext is embedded in a random image, and the image encryption method is used to double protection, and data recovery is finally achieved through a reversible process.
It improves the reliability and difficulty in cracking of data encryption, realizes dual protection and reversible recovery of data, and enhances data security.
Smart Images

Figure CN119720255A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of information technology security technology, and specifically relates to a data encryption and recovery method, device, equipment and medium based on XOR. Background Art
[0002] Data encryption is a process of converting raw data (plain text) into a format (cipher text) that can only be interpreted by authorized users through algorithms. The key to this process is the key, which is an indispensable element in the encryption and decryption process. Data encryption is an indispensable part of today's digital age. With the rise of the digital economy, data has become an important production factor for economic development. If data is leaked or abused, it will have a serious impact on the economic and social order. Therefore, strengthening data encryption protection can maintain social stability and promote economic development. Summary of the invention
[0003] In order to solve the above problems existing in the prior art, the present invention provides a data encryption and recovery method, device, equipment and medium based on XOR.
[0004] The purpose of the present invention can be achieved through the following technical solutions: A data encryption and recovery method based on XOR, the implementation of the data encryption and recovery method comprises the following steps: Get plaintext data and key , encrypting the plaintext data by an optimized XOR algorithm to obtain an initial ciphertext, wherein the optimized XOR algorithm is a reversible algorithm; Disordering the characters in the initial ciphertext according to a predetermined rule to form a disordered ciphertext; The random ciphertext is embedded in a random image to obtain an image to be encrypted, and the image to be encrypted is encrypted by an image encryption method to obtain an encrypted image, wherein the image encryption method is a reversible method; The encrypted image is decrypted through a reversible process to achieve a data recovery process.
[0005] Preferably, the optimized XOR algorithm specifically includes: Traverse the plaintext data and the key and perform an XOR operation on each character of the plaintext data and the corresponding character of the key to obtain an XOR ciphertext sequence ,in, is the exclusive OR operator; Randomly embed the least significant bit, the least significant bit includes the first least significant bit, the second least significant bit, ..., the nth least significant bit, and perform XOR operation on the remaining least significant bits in pairs starting from the first least significant bit, to obtain calculation bits, arranging the calculation bits in order and extracting the first N calculation bits to form a calculation bit sequence; The initial ciphertext is obtained by performing an XOR operation on each character of the XOR ciphertext sequence and the corresponding character of the calculation bit sequence through the XOR algorithm.
[0006] Preferably, the image encryption method specifically includes: Preset an image key, the image key includes a first image key and a second image key, encrypt the image to be encrypted based on the image key and generate a pseudo-random sequence, the pseudo-random sequence includes a first pseudo-random sequence and a second pseudo-random sequence, which correspond to the first image key and the second image key respectively; Decomposing the image to be encrypted into pixel matrices according to RGB channels, wherein the pixel matrices include pixel matrix R, pixel matrix G, and pixel matrix B; Encrypt the pixel matrix by using an XOR algorithm to obtain an encrypted pixel matrix, wherein the encrypted pixel matrix includes an encrypted pixel matrix R, an encrypted pixel matrix G, and an encrypted pixel matrix B; Scrambling the encrypted pixel matrix by discrete wavelet transform to obtain a scrambled encrypted image; The scrambled encrypted image is again XOR-encrypted using the pseudo-random sequence to obtain the encrypted image.
[0007] Preferably, encrypting the pixel matrix by using an XOR algorithm to obtain an encrypted pixel matrix comprises: An initial matrix is randomly preset, and the initial matrix and the pixel matrix R are encrypted by an XOR algorithm to obtain the encrypted pixel matrix R; Performing XOR algorithm encryption on the encrypted pixel matrix R and the pixel matrix G to obtain the encrypted pixel matrix G; The encrypted pixel matrix G and the pixel matrix B are encrypted using an XOR algorithm to obtain the encrypted pixel matrix B.
[0008] Preferably, the mathematical description of performing XOR algorithm encryption on the initial matrix and the pixel matrix R is: , where U R is the encrypted pixel matrix R, E(·) is the encryption process, Q is the image key, R is the pixel matrix R, and I is the initial matrix; the mathematical description of performing XOR algorithm encryption on the encrypted pixel matrix R and the pixel matrix G is as follows: , where U G is the encrypted pixel matrix G, G is the pixel matrix G; the mathematical description of performing XOR algorithm encryption on the encrypted pixel matrix G and the pixel matrix B is as follows: , where U B is the encrypted pixel matrix B, and B is the pixel matrix B.
[0009] Preferably, the step of scrambling the encrypted pixel matrix by discrete wavelet transform to obtain a scrambled encrypted image comprises: Decomposing the encrypted pixel matrix into a high-frequency part and a low-frequency part based on the discrete wavelet transform, and further decomposing the high-frequency part and the low-frequency part to obtain a secondary high-frequency part and a secondary low-frequency part; The low-frequency part and the secondary low-frequency part are scrambled by the first pseudo-random sequence to obtain a low-frequency scrambled matrix, the high-frequency part and the secondary high-frequency part are scrambled by the second pseudo-random sequence to obtain a high-frequency scrambled matrix, and the low-frequency scrambled matrix and the high-frequency scrambled matrix are recombined to obtain the scrambled encrypted image.
[0010] Preferably, the step of re-XOR encrypting the scrambled encrypted image by using the pseudo-random sequence to obtain the encrypted image comprises: Extracting F elements in the pseudo-random sequence in sequence, where F is consistent with the size of the scrambled encrypted image; XOR algorithm encryption is performed between the selected single element and the pixel points of the scrambled encrypted image to obtain the encrypted image.
[0011] A data encryption and recovery device based on XOR, used to execute the data encryption and recovery method described above, comprising an initial encryption module, a disorder processing module, an image encryption module, and a data recovery module; The initial encryption module is used to obtain plaintext data and key , encrypting the plaintext data by an optimized XOR algorithm to obtain an initial ciphertext, wherein the optimized XOR algorithm is a reversible algorithm; The disorder processing module is used to shuffle the characters in the initial ciphertext according to a predetermined rule to form disordered ciphertext; The image encryption module is used to embed the random ciphertext into a random image to obtain an image to be encrypted, and encrypt the image to be encrypted by an image encryption method to obtain an encrypted image, wherein the image encryption method is a reversible method; The data recovery module is used to decrypt the encrypted image through a reversible process to achieve a data recovery process.
[0012] An electronic device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned data encryption and recovery method when executing the program.
[0013] A storage medium containing computer executable instructions, wherein the computer executable instructions are used to perform the above-mentioned data encryption and recovery method when executed by a computer processor.
[0014] The beneficial effects of the present invention are: (1) By optimizing the XOR algorithm to encrypt plaintext data and improving the basic XOR algorithm by combining the least significant bit, the data encryption process is more reliable and difficult to crack.
[0015] (2) The disordered ciphertext is embedded into the random image to obtain the image to be encrypted, and the image to be encrypted is encrypted by the image encryption method to achieve double protection of the data. The image encryption method combines pseudo-random sequence and discrete wavelet transform, and the encrypted image is more disordered, further ensuring data security.
[0016] (3) The pixel matrix is encrypted layer by layer through the initial matrix, and each step is linked together, making the encryption process more reliable.
[0017] (4) The encryption process of this application is a reversible process, which facilitates decryption by authorized parties. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to facilitate understanding by those skilled in the art, the present invention is further described below with reference to the accompanying drawings.
[0019] Figure 1 The present invention is a flowchart of the steps of a data encryption and recovery method based on XOR. DETAILED DESCRIPTION
[0020] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the specific implementation methods, structures, features and effects of the present invention are described in detail below in conjunction with the accompanying drawings and preferred embodiments.
[0021] The working principle and use process of the present invention: See also Figure 1 , a data encryption and recovery method based on XOR, comprising: S1: Get plaintext data (such as K={1,2,3,4,5}) and the key (e.g., T={1,5,2,4,3}), encrypt the plaintext data by optimizing the XOR algorithm to obtain the initial ciphertext (e.g., {1,6,1,1,7}), the optimized XOR algorithm is a reversible algorithm, that is, it can be decrypted by the inverse process; S2: shuffle the characters in the initial ciphertext according to a predetermined rule to form a random ciphertext. The predetermined rule can be formulated according to needs. For example, it can be stipulated that the nth digit in the order and the nth digit in the reverse order are exchanged, that is, the initial ciphertext {1,6,1,1,7} can be obtained as the random ciphertext {7,1,1,6,1}; S3: embedding the random ciphertext into a random image to obtain an image to be encrypted (the image to be encrypted at this time is a normal image embedded with numbers), encrypting the image to be encrypted by an image encryption method to obtain an encrypted image (the encrypted image at this time cannot be distinguished by the naked eye, similar to a mosaic image), and the image encryption method is a reversible method; S4: Decrypting the encrypted image through a reversible process to achieve a data recovery process.
[0022] In this embodiment, the optimized XOR algorithm is specifically: S101: traverse the plaintext data and the key and perform an XOR operation on each character of the plaintext data and the corresponding character of the key to obtain an XOR ciphertext sequence ,in, XOR operator. For example, when the plaintext data is K={1,2,3,4,5} and the secret key is T={1,5,2,4,3}, the plaintext data and the secret key are converted into binary respectively, that is, K={0001,0010,0011,0100,0101}, T={0001,0101,0010,0100,0011}, and the XOR operation of K and T is performed to obtain the binary result {0000,0111,0001,0000,0110}, which is then converted into decimal to obtain the XOR ciphertext sequence KT={0,7,1,0,6}. S102: Randomly embed the least significant bit, the least significant bit includes the first least significant bit, the second least significant bit, ..., the nth least significant bit, and perform XOR operation on the remaining least significant bits in pairs starting from the first least significant bit to obtain calculation bits, arranging the calculation bits in order and extracting the first N calculation bits to form a calculation bit sequence, for example, randomly embedding the least significant bits {0,1,1,0,1,1}, performing XOR operations on two of them to obtain {1,1,0,1,1,0,1,0,0,1,0,0,1,1,0}, and extracting the first 5 bits to obtain the calculation bit sequence {1,1,0,1,1}; S103: Perform an XOR operation on each bit character of the XOR ciphertext sequence and the corresponding bit character of the calculation bit sequence through the XOR algorithm to obtain the initial ciphertext. For example, perform an XOR operation on the XOR ciphertext sequence KT={0,7,1,0,6} and the calculation bit sequence {1,1,0,1,1} to obtain the initial ciphertext {1,6,1,1,7}.
[0023] In this embodiment, the image encryption method is specifically: S301: Preset an image key, the image key includes a first image key and a second image key, encrypt the image to be encrypted based on the image key and generate a pseudo-random sequence, the pseudo-random sequence includes a first pseudo-random sequence and a second pseudo-random sequence, which correspond to the first image key and the second image key respectively; S302: Decomposing the image to be encrypted into pixel matrices according to RGB channels, wherein the pixel matrices include pixel matrix R, pixel matrix G, and pixel matrix B; S303: Encrypting the pixel matrix by an XOR algorithm to obtain an encrypted pixel matrix, wherein the encrypted pixel matrix includes an encrypted pixel matrix R, an encrypted pixel matrix G, and an encrypted pixel matrix B; S304: Scrambling the encrypted pixel matrix by discrete wavelet transform to obtain a scrambled encrypted image; S305: XOR-encrypting the scrambled encrypted image again with the pseudo-random sequence to obtain the encrypted image.
[0024] In this embodiment, the pixel matrix is encrypted by using an XOR algorithm to obtain an encrypted pixel matrix, which can be implemented by the following steps: S303-1: randomly preset an initial matrix, and perform XOR algorithm encryption on the initial matrix and the pixel matrix R, which is mathematically described as , where U R is the encrypted pixel matrix R, E(·) is the encryption process, Q is the image key, R is the pixel matrix R, and I is the initial matrix. That is, the values of the corresponding positions of the initial matrix and the pixel matrix R are encrypted by the above XOR algorithm to obtain a new encrypted pixel matrix R; S303-2: Encrypt the encrypted pixel matrix R and the pixel matrix G using an XOR algorithm, which is mathematically described as , where U G is the encrypted pixel matrix G, G is the pixel matrix G, that is, the values of the corresponding positions of the encrypted pixel matrix R and the pixel matrix G are encrypted by the above XOR algorithm to obtain a new encrypted pixel matrix G; S303-3: Encrypt the encrypted pixel matrix G and the pixel matrix B using an XOR algorithm, which is mathematically described as , where U B is the encrypted pixel matrix B, B is the pixel matrix B, that is, the values of the corresponding positions of the encrypted pixel matrix G and the pixel matrix B are encrypted by the above XOR algorithm to obtain a new encrypted pixel matrix B.
[0025] In this embodiment, the encrypted pixel matrix is scrambled by discrete wavelet transform to obtain a scrambled encrypted image, which can be specifically implemented by the following steps: S304-1: decomposing the encrypted pixel matrix into a high-frequency part and a low-frequency part based on the discrete wavelet transform (a total of 3 encrypted pixel matrices can be decomposed into 3 high-frequency parts and 3 low-frequency parts), and continuing to decompose the high-frequency part and the low-frequency part to obtain secondary high-frequency parts and secondary low-frequency parts (a total of 12); S304-2: Scramble the low-frequency part and the secondary low-frequency part using the first pseudo-random sequence to obtain a low-frequency scrambled matrix, scramble the high-frequency part and the secondary high-frequency part using the second pseudo-random sequence to obtain a high-frequency scrambled matrix, and recombine the low-frequency scrambled matrix and the high-frequency scrambled matrix to obtain the scrambled encrypted image.
[0026] In this embodiment, the encrypted image is obtained by XOR-encrypting the scrambled encrypted image again with the pseudo-random sequence, which can be specifically implemented by the following steps: S305-1: extract F elements in the pseudo-random sequence in sequence, where F is consistent with the size of the scrambled encrypted image. For example, if the size of the scrambled encrypted image is 390×260, then F=390×260; S305-2: Perform XOR encryption between the selected single element and the pixel points of the scrambled encrypted image respectively to obtain the encrypted image.
[0027] A data encryption and recovery device based on XOR, comprising an initial encryption module, a disorder processing module, an image encryption module, and a data recovery module; The initial encryption module is used to obtain plaintext data and key , encrypting the plaintext data by an optimized XOR algorithm to obtain an initial ciphertext, wherein the optimized XOR algorithm is a reversible algorithm, that is, decryption can be performed by an inverse process; The disorder processing module is used to shuffle the characters in the initial ciphertext according to a predetermined rule to form a disordered ciphertext, and the predetermined rule can be formulated according to requirements; The image encryption module is used to embed the random ciphertext into a random image to obtain an image to be encrypted, and encrypt the image to be encrypted by an image encryption method to obtain an encrypted image, wherein the image encryption method is a reversible method; The data recovery module is used to decrypt the encrypted image through a reversible process to achieve a data recovery process.
[0028] The computer storage medium of the embodiment of the present invention may adopt any combination of one or more computer-readable media. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device.
[0029] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0030] The program code included on the computer readable medium can be transmitted with any appropriate medium, including but not limited to wireless, electric wire, optical cable, RF, etc., or any suitable combination of the above. The computer program code for performing the operation of the present invention can be written in one or more programming languages or their combinations, and the programming language includes object-oriented programming languages-such as Java, Smalltalk, C++, and also includes conventional procedural programming languages-such as "C" language or similar programming languages. The program code can be executed completely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on the remote computer, or completely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0031] The above description is only a preferred embodiment of the present invention and does not limit the present invention in any form. Although the present invention has been disclosed as a preferred embodiment as above, it is not used to limit the present invention. Any technical personnel in this field can make some changes or modify the technical contents disclosed above into equivalent embodiments without departing from the scope of the technical solution of the present invention. However, any simple modification, equivalent change and modification made to the above embodiments according to the technical essence of the present invention without departing from the content of the technical solution of the present invention still fall within the scope of the technical solution of the present invention.
Claims
1. A data encryption and recovery method based on XOR, characterized in that: The implementation of the data encryption and recovery method includes the following steps: Get plaintext data and key , encrypting the plaintext data by an optimized XOR algorithm to obtain an initial ciphertext, wherein the optimized XOR algorithm is a reversible algorithm; Disordering the characters in the initial ciphertext according to a predetermined rule to form a disordered ciphertext; The random ciphertext is embedded in a random image to obtain an image to be encrypted, and the image to be encrypted is encrypted by an image encryption method to obtain an encrypted image, wherein the image encryption method is a reversible method; The encrypted image is decrypted through a reversible process to achieve a data recovery process.
2. The data encryption and recovery method according to claim 1, characterized in that: The optimized XOR algorithm specifically includes: Traverse the plaintext data and the key and perform an XOR operation on each character of the plaintext data and the corresponding character of the key to obtain an XOR ciphertext sequence ,in, is the exclusive OR operator; Randomly embed the least significant bit, the least significant bit includes the first least significant bit, the second least significant bit, ..., the nth least significant bit, and perform XOR operation on the remaining least significant bits in pairs starting from the first least significant bit, to obtain calculation bits, arranging the calculation bits in order and extracting the first N calculation bits to form a calculation bit sequence; The initial ciphertext is obtained by performing an XOR operation on each character of the XOR ciphertext sequence and the corresponding character of the calculation bit sequence through the XOR algorithm.
3. The data encryption and recovery method according to claim 1, characterized in that: The image encryption method specifically includes: Preset an image key, the image key includes a first image key and a second image key, encrypt the image to be encrypted based on the image key and generate a pseudo-random sequence, the pseudo-random sequence includes a first pseudo-random sequence and a second pseudo-random sequence, which correspond to the first image key and the second image key respectively; Decomposing the image to be encrypted into pixel matrices according to RGB channels, wherein the pixel matrices include pixel matrix R, pixel matrix G, and pixel matrix B; Encrypt the pixel matrix by using an XOR algorithm to obtain an encrypted pixel matrix, wherein the encrypted pixel matrix includes an encrypted pixel matrix R, an encrypted pixel matrix G, and an encrypted pixel matrix B; Scrambling the encrypted pixel matrix by discrete wavelet transform to obtain a scrambled encrypted image; The scrambled encrypted image is again XOR-encrypted using the pseudo-random sequence to obtain the encrypted image.
4. The data encryption and recovery method according to claim 3, characterized in that: Encrypting the pixel matrix by using the XOR algorithm to obtain an encrypted pixel matrix includes: An initial matrix is randomly preset, and the initial matrix and the pixel matrix R are encrypted by an XOR algorithm to obtain the encrypted pixel matrix R; Performing XOR algorithm encryption on the encrypted pixel matrix R and the pixel matrix G to obtain the encrypted pixel matrix G; The encrypted pixel matrix G and the pixel matrix B are encrypted using an XOR algorithm to obtain the encrypted pixel matrix B.
5. The data encryption and recovery method according to claim 4, characterized in that: The mathematical description of performing XOR algorithm encryption on the initial matrix and the pixel matrix R is: , where U R is the encrypted pixel matrix R, E(·) is the encryption process, Q is the image key, R is the pixel matrix R, and I is the initial matrix; the mathematical description of performing XOR algorithm encryption on the encrypted pixel matrix R and the pixel matrix G is as follows: , where U G is the encrypted pixel matrix G, G is the pixel matrix G; the mathematical description of performing XOR algorithm encryption on the encrypted pixel matrix G and the pixel matrix B is as follows: , where U B is the encrypted pixel matrix B, and B is the pixel matrix B.
6. The data encryption and recovery method according to claim 3, characterized in that: The step of scrambling the encrypted pixel matrix by discrete wavelet transform to obtain a scrambled encrypted image comprises: Decomposing the encrypted pixel matrix into a high-frequency part and a low-frequency part based on the discrete wavelet transform, and further decomposing the high-frequency part and the low-frequency part to obtain a secondary high-frequency part and a secondary low-frequency part; The low-frequency part and the secondary low-frequency part are scrambled by the first pseudo-random sequence to obtain a low-frequency scrambled matrix, the high-frequency part and the secondary high-frequency part are scrambled by the second pseudo-random sequence to obtain a high-frequency scrambled matrix, and the low-frequency scrambled matrix and the high-frequency scrambled matrix are recombined to obtain the scrambled encrypted image.
7. The data encryption and recovery method according to claim 3, characterized in that: The step of XOR-encrypting the scrambled encrypted image again by using the pseudo-random sequence to obtain the encrypted image comprises: Extracting F elements in the pseudo-random sequence in sequence, where F is consistent with the size of the scrambled encrypted image; XOR algorithm encryption is performed between the selected single element and the pixel points of the scrambled encrypted image to obtain the encrypted image.
8. A data encryption and recovery device based on XOR, characterized in that: The device is applied to the data encryption and recovery method as described in any one of claims 1 to 7, comprising an initial encryption module, a disorder processing module, an image encryption module, and a data recovery module; The initial encryption module is used to obtain plaintext data and key , encrypting the plaintext data by an optimized XOR algorithm to obtain an initial ciphertext, wherein the optimized XOR algorithm is a reversible algorithm; The disorder processing module is used to shuffle the characters in the initial ciphertext according to a predetermined rule to form disordered ciphertext; The image encryption module is used to embed the random ciphertext into a random image to obtain an image to be encrypted, and encrypt the image to be encrypted by an image encryption method to obtain an encrypted image, wherein the image encryption method is a reversible method; The data recovery module is used to decrypt the encrypted image through a reversible process to implement a data recovery process.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the data encryption and recovery method as described in any one of claims 1-7 is implemented.
10. A storage medium containing computer executable instructions, characterized in that: The computer executable instructions are used to execute the data encryption and recovery method as described in any one of claims 1-7 when executed by a computer processor.
Citation Information
Patent Citations
Information hiding method based on P tensor secret sharing and multiple data hiding devices
CN115002291A
Image encryption method based on Hamiltonian conservative chaotic system and two-dimensional discrete wavelet transform
CN115022484A
High-embedding-rate reversible data hiding method based on robust Chinese remainder theorem coding
CN118509535A