Method and apparatus for data encryption, and method and apparatus for data decryption
The keys are generated by Sudoku riddles and encrypted and decrypted using different riddles, which solves the information leakage problem caused by key leakage in stream encryption algorithms, and improves the security of data transmission.
Patent Information
- Application Number
- CN202111355575.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-16
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2041-11-16
AI Technical Summary
In existing stream encryption algorithms, encryption and decryption use the same pseudo-random encrypted data stream as the key, resulting in the problem of information data leakage in the case of key leakage.
By calculating the answer to the Sudoku riddle, generating the key, and using different riddles for encryption and decryption, hiding the same key in the symmetric encryption algorithm, generating encrypted data and sending the second riddle to the receiver.
Improve the security of data transmission, prevent information and data leakage caused by key leakage, and enhance the security of data transmission.
Smart Images

Figure CN114021174B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of data encryption and decryption. Specifically, it relates to a method and device for data encryption and a method and device for data decryption. Background Art
[0002] When information is transmitted, to ensure the security of important information, it is usually encrypted before transmission to prevent information data leakage, and decrypted after transmission. Stream encryption algorithms are usually used for encryption and decryption.
[0003] Specifically, the stream cipher is a symmetric encryption algorithm. The encryption and decryption parties use the same pseudo-random encryption data stream as the key. Each piece of plaintext data is sequentially encrypted with the key data stream to obtain the ciphertext data stream. The ciphertext stream data can be sequentially decrypted with the key data stream to obtain the plaintext data stream.
[0004] In related technologies, stream encryption algorithms such as the Rc4 (Rivest Cipher 4) algorithm and the Salsa20 algorithm are used to generate pseudo-random encryption data streams for encryption. Among them, the Rc4 algorithm initializes the secret key. According to the input secret key key, it uses the Key-Scheduling Algorithm (KSA) to generate a 256-byte sbox (substitution box); then it obtains the key stream through the Pseudo-Random Generation Algorithm (PRGA); during encryption, the key stream is XORed with the plaintext to obtain the ciphertext, and during decryption, the ciphertext is XORed with the key stream to obtain the plaintext. The principle of Salsa20 is to generate a pseudo-random byte stream that is indistinguishable from a truly random byte stream in a very long range (about 2 to the 70th power), achieving an effect equivalent to that of the One-Time Pad (OTP) encryption. The generation of the pseudo-random number stream is actually a process of sending 64 bytes (512 bits) of input into the core function and then obtaining 512 bits of output. Each input byte contains the key, the initial vector, and the counter. In this way, to generate a pseudo-random number stream of length N bytes, it is only necessary to call the core function several times until enough length (not less than N) of output is obtained.
[0005] However, the above stream encryption algorithms in related technologies are symmetric encryption algorithms. The encryption and decryption parties use the same pseudo-random encryption data stream as the key. After the data encryption end encrypts the information data, the key information is easily leaked during transmission, resulting in information data leakage.
[0006] In the related art, when using a stream encryption algorithm, the encryption key and the decryption key are the same, resulting in information data leakage in the case of key leakage. At present, no effective solution has been proposed. Summary of the Invention
[0007] The present application provides a method and apparatus for data encryption and a method and apparatus for data decryption to solve the problem in the related art that when using a stream encryption algorithm, the encryption key and the decryption key are the same, resulting in information data leakage in the case of key leakage.
[0008] According to one aspect of the present application, a data encryption method is provided. The method includes: calculating the solution corresponding to the first puzzle of a Sudoku, where the first solution is composed of a first preset number of digits on the Sudoku board, and the solution is composed of all the digits on the Sudoku board; generating a key through the digits in the solution, and generating a second puzzle through a second preset number of digits in the solution; encrypting the data to be encrypted with the key to generate encrypted data, and sending the encrypted data and the second puzzle to a data receiving end.
[0009] Optionally, before calculating the solution corresponding to the first puzzle of the Sudoku, the method further includes: setting the first preset number of digits at any position on the Sudoku board to obtain a first puzzle, where the first preset number is greater than or equal to 17.
[0010] Optionally, generating a key through the digits in the solution includes: selecting digits from the solution and using the selected digits as candidate digits, where the candidate digits are all or part of the digits in the solution; combining the candidate digits according to a preset rule to obtain a key.
[0011] Optionally, encrypting the data to be encrypted with the key to generate encrypted data includes: determining the numerical values corresponding to the respective digits in the key to obtain a plurality of numerical values; in the case where the length of the data to be encrypted is less than or equal to the length of the key, traversing the plurality of numerical values, and encrypting the corresponding number of data in the data to be encrypted with each numerical value in turn to obtain a plurality of encrypted digits, and combining the plurality of encrypted digits into encrypted data, where the corresponding number is the number indicated by the numerical value; in the case where the length of the data to be encrypted is greater than the length of the key, traversing the plurality of numerical values multiple times, and encrypting the corresponding number of data in the data to be encrypted with each numerical value in turn until all the data in the data to be encrypted is encrypted, to obtain a plurality of encrypted digits, and combining the plurality of encrypted digits into encrypted data.
[0012] Optionally, encrypt the corresponding amount of data in the data to be encrypted one by one with each numerical value to obtain multiple encrypted numbers, including: determining the data with the corresponding number of bits in the data to be encrypted according to each numerical value to obtain the corresponding amount of data, and converting the corresponding amount of data into decimal data; sequentially calculating each numerical value and the corresponding decimal data according to a preset calculation rule to obtain multiple encrypted numbers, where the preset calculation rule is at least one of the following: addition, subtraction, multiplication, and division.
[0013] Optionally, encrypt the data to be encrypted with a key to generate encrypted data, including: grouping the data to be encrypted to obtain multiple groups of data; encrypting each group of data with the key respectively to obtain multiple first encrypted data; combining the multiple first encrypted data into encrypted data.
[0014] According to another aspect of the present application, a decryption method is provided. Decrypt the data encrypted by any one of the above data encryption methods. The method includes: receiving the encrypted data and the second riddle of the Sudoku sent by the sending end; calculating the answer of the Sudoku through the second riddle, where the second riddle is composed of the data of the second preset amount in the answer; generating a key through the data in the answer; decrypting the encrypted data with the key to obtain decrypted data.
[0015] Optionally, generating a key through the numbers in the answer includes: selecting numbers from the answer and using the selected numbers as candidate numbers, where the candidate numbers are all or part of the numbers in the answer; combining the candidate numbers according to a preset rule to obtain a key.
[0016] Optionally, decrypting the encrypted data with the key to obtain decrypted data includes: determining the numerical values corresponding to each number in the key to obtain multiple numerical values; when the length of the encrypted data is less than or equal to the length of the key, traversing the multiple numerical values, and calculating each decimal number in the encrypted data one by one with each numerical value according to a preset calculation rule to obtain multiple calculated data, where the preset calculation rule is at least one of the following: addition, subtraction, multiplication, and division; when the length of the encrypted data is greater than the length of the key, traversing the multiple numerical values multiple times, and calculating each decimal number in the encrypted data one by one with each numerical value according to a preset calculation rule until all the data in the encrypted data are decrypted to obtain the calculated data; converting each calculated data into binary data to obtain multiple groups of binary data, and the multiple groups of binary data constitute the decrypted data.
[0017] According to another aspect of the present application, a data encryption device is provided. The device includes: a first calculation unit configured to calculate the solution corresponding to the first riddle of a Sudoku, wherein the first solution is composed of a first preset number of digits on the Sudoku board, and the solution is composed of all the digits on the Sudoku board; a first generation unit configured to generate a key through the digits in the solution, and generate a second riddle through a second preset number of digits in the solution; an encryption unit configured to encrypt the data to be encrypted through the key to generate encrypted data, and send the encrypted data and the second riddle to a data receiving end.
[0018] According to another aspect of the present application, a decryption device is provided. It decrypts the data encrypted by the above data encryption device. The device includes: a receiving unit configured to receive the encrypted data sent by a sending end and the second riddle of the Sudoku; a second calculation unit configured to calculate the solution of the Sudoku through the second riddle, wherein the second riddle is composed of a second preset number of data in the solution; a second generation unit configured to generate a key through the data in the solution; a decryption unit configured to decrypt the encrypted data through the key to obtain decrypted data.
[0019] Through the present application, the following steps are adopted: calculating the solution corresponding to the first riddle of a Sudoku, wherein the first solution is composed of a first preset number of digits on the Sudoku board, and the solution is composed of all the digits on the Sudoku board; generating a key through the digits in the solution, and generating a second riddle through a second preset number of digits in the solution; encrypting the data to be encrypted through the key to generate encrypted data, and sending the encrypted data and the second riddle to a data receiving end, which solves the problem in the related art that when using a stream encryption algorithm, the encryption key and the decryption key are the same, resulting in information data leakage in the case of key leakage. By setting different riddles with the same solution as the encrypted data and the decrypted data, the effect of hiding the same key in the symmetric encryption algorithm is achieved, thereby improving the security of data transmission. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings constituting a part of this application are used to provide a further understanding of this application. The schematic embodiments of this application and their descriptions are used to explain this application and do not constitute an improper limitation to this application. In the drawings:
[0021] Figure 1 is a flowchart of a data encryption method provided according to an embodiment of the present application;
[0022] Figure 2 is a schematic diagram of an optional riddle of a Sudoku provided according to an embodiment of the present application;
[0023] Figure 3 is a schematic diagram of an optional solution of a Sudoku provided according to an embodiment of the present application;
[0024] Figure 4 It is another optional schematic diagram of the puzzle of Sudoku provided according to an embodiment of the present application;
[0025] Figure 5 It is a flowchart of a data decryption method provided according to an embodiment of the present application;
[0026] Figure 6 It is a schematic diagram of a data encryption device provided according to an embodiment of the present application;
[0027] Figure 7 It is a schematic diagram of a data decryption device provided according to an embodiment of the present application. Detailed implementation manners
[0028] It should be noted that, without conflict, the embodiments in the present application and the features in the embodiments may be combined with each other. The present application will be described in detail below with reference to the drawings and in conjunction with the embodiments.
[0029] In order to enable those skilled in the art to better understand the solution of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0030] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above drawings are used to distinguish similar objects, and do not necessarily need to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances so as to describe the embodiments of the present application here. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device including a series of steps or units does not necessarily need to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0031] According to an embodiment of the present application, a data encryption method is provided.
[0032] Figure 1 It is a flowchart of the data encryption method according to an embodiment of the present application. As Figure 1 shown, the method includes the following steps:
[0033] Step S102, calculate the solution corresponding to the first puzzle of the Sudoku, where the first solution is composed of a first preset number of digits on the Sudoku board, and the solution is composed of all the digits on the Sudoku board.
[0034] Specifically, the first preset quantity may be the number of digits included in the puzzle of the sudoku set in advance, for example, 20 digits. Through the preset 20 digits, the solution of the sudoku corresponding to the puzzle of the sudoku can be calculated. Figure 2 It is a schematic diagram of an optional puzzle of the sudoku provided according to an embodiment of the present application, that is, a schematic diagram of the first puzzle. As Figure 2 shown, the sudoku board contains 17 determined digits. Through computer calculation, the solution of the sudoku corresponding to the puzzle of the sudoku can be obtained. Figure 3 It is a schematic diagram of an optional solution of the sudoku provided according to an embodiment of the present application. As Figure 3 shown, the solution of the sudoku is all the digits on the sudoku board, that is, 81 determined data.
[0035] Step S104, generate a key from the digits in the solution, and generate a second puzzle from the second preset quantity of digits in the solution.
[0036] Specifically, the solution contains 81 digits. These 81 digits can be arranged and combined. For example, traversing horizontally according to a 9×9 board to obtain a data with a length of 81 digits, and setting this data as the key. Or select some digits from the 81 data, for example, select the digits in the odd rows for traversal to obtain a data composed of 45 digits, and set this data as the key.
[0037] It should be noted that the second puzzle may be the puzzle of the sudoku with the same solution as the first puzzle. Figure 4 It is another schematic diagram of an optional puzzle of the sudoku provided according to an embodiment of the present application, that is, a schematic diagram of the second puzzle. As Figure 4 shown, the number and position of the digits on the sudoku board may be different from those of the first puzzle, but by calculating the second puzzle, a solution can be obtained that is the same as the solution of the sudoku calculated from the Figure 3 shown first puzzle.
[0038] Step S106, encrypt the data to be encrypted with the key to generate encrypted data, and send the encrypted data and the second puzzle to the data receiving end.
[0039] Specifically, use the obtained key to encrypt the data to be encrypted. For example, encryption can be performed by multiplying or adding each digit one by one to obtain encrypted data, and send the encrypted data and the second puzzle to the data receiving end, so that the puzzles for obtaining the encryption key and the decryption key are different, and the hiding of the key is completed.
[0040] The data encryption method provided by the embodiments of the present application calculates the solution corresponding to the first riddle of the Sudoku. Among them, the first solution is composed of the first preset number of digits on the Sudoku board, and the solution is composed of all the digits on the Sudoku board; generates a key through the digits in the solution, and generates a second riddle through the second preset number of digits in the solution; encrypts the data to be encrypted with the key to generate encrypted data, and sends the encrypted data and the second riddle to the data receiving end. This solves the problem in the related art that when using the stream encryption algorithm, the encryption key and the decryption key are the same, resulting in information data leakage in the case of key leakage. By setting different riddles with the same solution as the encrypted data and the decrypted data, the effect of hiding the same key in the symmetric encryption algorithm is achieved, thereby improving the security of data transmission.
[0041] Optionally, in the data encryption method provided by the embodiments of the present application, before calculating the solution corresponding to the first riddle of the Sudoku, the method further includes: setting the first preset number of digits at any position on the Sudoku board to obtain the first riddle, where the first preset number is greater than or equal to 17.
[0042] It should be noted that Sudoku is a mathematical game originating from Switzerland in the 18th century. Based on the known digits on the 9×9 board, all the remaining blank space digits are deduced, and each row, each column, and each thick-line palace (3*3) contains the digits 1-9 without repetition. For a Sudoku riddle, as long as at least 17 known digit elements are determined, all the remaining undetermined digit elements can be determined. Therefore, when setting the riddle, setting more than or equal to 17 known digits can determine the solution of the Sudoku. Even if the number and position of the digits set in different riddles are different, the same solution can be calculated.
[0043] For example, Figure 2 sets 17 digits, Figure 4 sets 20 digits, and the digit positions are all different, but the two riddles can obtain the same solution after calculation.
[0044] In order to obtain a key with a relatively high security level through the solution, optionally, in the data encryption method provided by the embodiments of the present application, generating a key through the digits in the solution includes: selecting digits from the solution and using the selected digits as candidate digits, where the candidate digits are all or part of the digits in the solution; combining the candidate digits according to a preset rule to obtain the key.
[0045] Specifically, selecting candidate digits from the solution can be to select all or part of the 81 digits in the solution, or repeat the selection of part of the digits. For example, you can select Figure 3For the even - numbered digits in it, traverse to obtain 36 digits, or repeat the selection of the digits in the second row 5 times to obtain 45 digits.
[0046] It should be noted that after selecting the candidate digits, the candidate digits can be combined. For example, traverse the candidate digits in the order from top to bottom and from left to right, or subtract 1 from each digit to obtain new candidate digits, then traverse the new candidate digits, and set the combined digits as the key.
[0047] After selecting the key, the encryption method needs to be selected. Optionally, in the data encryption method provided in the embodiments of the present application, encrypt the data to be encrypted with the key to generate encrypted data, including: determining the numerical values corresponding to each digit in the key to obtain multiple numerical values; when the length of the data to be encrypted is less than or equal to the length of the key, traverse the multiple numerical values, and encrypt the corresponding number of data in the data to be encrypted with each numerical value in turn to obtain multiple encrypted digits, and combine the multiple encrypted digits into encrypted data, where the corresponding number is the number indicated by the numerical value; when the length of the data to be encrypted is greater than the length of the key, traverse the multiple numerical values multiple times, and encrypt the corresponding number of data in the data to be encrypted with each numerical value in turn until all the data in the data to be encrypted is encrypted, to obtain multiple encrypted digits, and combine the multiple encrypted digits into encrypted data.
[0048] Specifically, the corresponding number is the number indicated by the numerical value. For example, the digit 8 in the key can correspond to 3 digits in the plaintext of the data to be encrypted, and the digit 6 in the key can correspond to 2 digits in the encrypted plaintext. After obtaining the key, determine the numerical value of each digit in the key, traverse all the numerical values, and encrypt the corresponding number of plaintexts for each numerical value. The encryption method can be to calculate the numerical value in the key and the corresponding number of numerical values in the plaintext, such as addition, subtraction and other calculation methods, to obtain the encrypted ciphertext, and send the ciphertext to the decryption end.
[0049] It should be noted that when the number of digits in the key is less than the number of digits in the plaintext, the digits in the key need to be reused in a loop. For example, when the key consists of 81 digits and the plaintext contains 810 digits, after encrypting the first 81 digits in the plaintext, start using the key from the first digit in the key again to encrypt the 82nd digit in the plaintext, until after looping 9 times, all 810 plaintext digits are encrypted, and the encrypted data is obtained.
[0050] To make the number of bytes for encrypting the plaintext random, optionally, in the data encryption method provided in the embodiments of the present application, each value is used to encrypt the corresponding number of data in the data to be encrypted in sequence, and a plurality of encrypted numbers are obtained, including: determining the data with the corresponding number of bits in the data to be encrypted according to each value to obtain the corresponding number of data, and converting the corresponding number of data into decimal data; sequentially calculating each value and the corresponding decimal data according to a preset calculation rule to obtain a plurality of encrypted numbers, where the preset calculation rule is at least one of the following: addition, subtraction, multiplication, and division.
[0051] Specifically, encrypt the plaintext in the data to be encrypted according to the corresponding number corresponding to the number in the key. It can be determined according to the value of the number. For example, the number 8 in the key can correspond to 3-bit data in the plaintext of the data to be encrypted, and the number 6 in the key can correspond to 2-bit data in the encrypted plaintext. Since the plaintext of the data to be encrypted is composed of binary data, after obtaining the corresponding number of data, the obtained plaintext data can be converted into decimal and subjected to the preset calculation rule to obtain the corresponding encrypted data. For example, the number 8 in the key can correspond to 3-bit data in the plaintext of the data to be encrypted, which is 110. Then convert 110 into decimal to get 6, and then perform subtraction calculation with the number in the key and 6 to get 2. Then use 2 as the encrypted data corresponding to 110 in the data to be encrypted. The calculation results of all the bit data in the data to be encrypted can be calculated in this way, and the calculation results are arranged in this order to obtain the encrypted data corresponding to the data to be encrypted.
[0052] There are various ways to encrypt the data to be encrypted through the key. Optionally, in the data encryption method provided in the embodiments of the present application, encrypt the data to be encrypted through the key to generate encrypted data, including: grouping the data to be encrypted to obtain multiple groups of data; using the key to encrypt each group of data respectively to obtain multiple first encrypted data; combining the multiple first encrypted data into encrypted data.
[0053] Specifically, the data to be encrypted can also be grouped. For example, every 27-bit data is a group, and three rows of data are selected from the solution of the sudoku as the key, and the key is used to encrypt each group of data. In addition, when the last data cannot make up 27 bits, it can be not encrypted and directly placed after each group of first encrypted data to obtain the encrypted data corresponding to the data to be encrypted.
[0054] Figure 5 It is a flowchart of the data decryption method according to the embodiments of the present application, decrypting the data encrypted by any one of the above data encryption methods. As Figure 5 shown, the method includes the following steps:
[0055] Step S502: Receive the encrypted data and the second riddle of the Sudoku sent by the sending end.
[0056] Specifically, the second riddle can be the riddle of a Sudoku with the same answer as the first riddle. Figure 4 It is another optional schematic diagram of the riddle of the Sudoku provided by the embodiment of the present application, that is, the schematic diagram of the second riddle. As Figure 4 shown, the number and position of the numbers in the Sudoku board can be different from those of the first riddle, but by calculating the second riddle, the same answer as the answer of the Sudoku calculated from the Figure 2 first riddle shown can be obtained. The key can be obtained through the second riddle to decrypt the encrypted data.
[0057] Step S504: Calculate the answer of the Sudoku through the second riddle, where the second riddle is composed of the second preset number of data in the answer.
[0058] Since the answer of the second riddle is the same as that of the first riddle, the same answer as the first riddle can be obtained by calculating the second riddle, and then the corresponding key is generated from the answer.
[0059] Step S508: Generate a key from the data in the answer.
[0060] Specifically, the answer contains 81 numbers. These 81 numbers can be arranged and combined. For example, traversing horizontally according to a 9×9 board, a data with a length of 81 numbers is obtained, and this data is set as the key. Or some numbers can be selected from the 81 numbers. For example, the numbers in the odd rows are selected for traversal to obtain a data composed of 45 numbers, and this data is set as the key. The calculation process in the key generation process needs to be the same as the calculation process for generating the key during encryption.
[0061] Step S508: Decrypt the encrypted data with the key to obtain the decrypted data.
[0062] After obtaining the key, the decrypted data is obtained through the inverse operation of the encryption process. For example, subtract the key from the encrypted data and perform binary conversion on the obtained data to obtain the initial plaintext data to be encrypted.
[0063] The data decryption method provided by the embodiments of the present application includes receiving encrypted data and the second riddle of a Sudoku sent by a sending end; calculating the solution of the Sudoku through the second riddle, where the second riddle is composed of the second preset number of data in the solution; generating a key through the data in the solution; and decrypting the encrypted data with the key to obtain decrypted data. This solves the problem in the related art that when using a stream encryption algorithm, the encryption key and the decryption key are the same, resulting in information data leakage in the case of key leakage. By setting different riddles with the same solution as the encrypted data and the decrypted data, the effect of hiding the same key in the symmetric encryption algorithm is achieved, thereby improving the security of data transmission.
[0064] Optionally, in the data decryption method provided by the embodiments of the present application, generating a key through the numbers in the solution includes: selecting numbers from the solution and using the selected numbers as candidate numbers, where the candidate numbers are all or part of the numbers in the solution; combining the candidate numbers according to a preset rule to obtain a key.
[0065] Specifically, selecting candidate numbers from the solution can be to select all or part of the 81 numbers in the solution, or repeatedly select part of the numbers. For example, one can select Figure 3 the numbers in the even rows, and traverse to obtain 36 numbers, or repeatedly select the numbers in the second row 5 times to obtain 45 numbers.
[0066] After selecting the candidate numbers, the candidate numbers can be combined. For example, traverse the candidate numbers in the order from top to bottom and from left to right, or subtract 1 from each number to obtain new candidate numbers, and then combine the new candidate numbers. The combined numbers are the key. It should be noted that the selected preset rule needs to be exactly the same as that selected during encryption.
[0067] Optionally, in the data decryption method provided by the embodiments of the present application, decrypting the encrypted data with the key to obtain decrypted data includes: determining the numerical values corresponding to each number in the key to obtain a plurality of numerical values; when the length of the encrypted data is less than or equal to the length of the key, traverse the plurality of numerical values, and calculate each decimal number in the encrypted data in turn according to a preset calculation rule by each numerical value to obtain a plurality of calculated data, and the preset calculation rule is at least one of the following: addition, subtraction, multiplication, and division; when the length of the encrypted data is greater than the length of the key, traverse the plurality of numerical values multiple times, and calculate each decimal number in the encrypted data in turn according to the preset calculation rule by each numerical value until all the data in the encrypted data are decrypted to obtain the calculated data; converting each calculated data into binary data to obtain multiple groups of binary data, and the decrypted data is composed of the multiple groups of binary data.
[0068] Specifically, after determining the values in the secret key, calculate the numbers in the encrypted data according to the pre-designed calculation rules. Among them, the pre-designed calculation rules need to be exactly the same as those in the encryption process. For example, if the secret key and the numbers are subtracted from each other during the encryption process to obtain the encrypted data, then during decryption, the secret key needs to be subtracted from the encrypted data to obtain the data to be processed. After traversing all the values in the encrypted data, convert all the data to be processed into binary to obtain the initial data to be encrypted.
[0069] It should be noted that when the number of digits in the secret key is less than the number of digits in the encrypted data, the digits in the secret key need to be reused in a loop. For example, when the secret key consists of 81 digits and the encrypted data contains 810 digits, after decrypting the first 81 digits of the encrypted data, start using the secret key again from the first digit of the secret key to decrypt the 82nd digit of the encrypted data until after 9 loops, all 810 digits are completely decrypted to obtain the decrypted data.
[0070] It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. And although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0071] The embodiment of the present application also provides a data encryption device. It should be noted that the data encryption device in the embodiment of the present application can be used to execute the data encryption method provided by the embodiment of the present application. The data encryption device provided by the embodiment of the present application will be introduced below.
[0072] Figure 6 is a schematic diagram of the data encryption device according to the embodiment of the present application. As Figure 6 shown, the device includes: a first calculation unit 601, a first generation unit 602, and an encryption unit 603.
[0073] Specifically, the first calculation unit 601 is used to calculate the answer corresponding to the first puzzle of the Sudoku, where the first answer is composed of the first preset number of digits on the Sudoku board, and the answer is composed of all the digits on the Sudoku board.
[0074] The first generation unit 602 is used to generate a secret key through the digits in the answer and generate a second puzzle through the second preset number of digits in the answer.
[0075] The encryption unit 603 is used to encrypt the data to be encrypted through the secret key, generate encrypted data, and send the encrypted data and the second puzzle to the data receiving end.
[0076] The data encryption device provided by the embodiment of the present application includes a first calculation unit 601 for calculating the solution corresponding to the first riddle of the Sudoku. The first solution is composed of a first preset number of digits on the Sudoku board, and the solution is composed of all the digits on the Sudoku board. A first generation unit 602 is used to generate a key through the digits in the solution and generate a second riddle through a second preset number of digits in the solution. An encryption unit 603 is used to encrypt the data to be encrypted through the key to generate encrypted data, and send the encrypted data and the second riddle to the data receiving end, which solves the problem that in the related art, when using a stream encryption algorithm, the encryption key and the decryption key are the same, resulting in information data leakage in the case of key leakage. By setting different riddles of the same solution as the encrypted data and the decrypted data, the effect of hiding the same key in the symmetric encryption algorithm is achieved, thereby improving the security of data transmission.
[0077] Optionally, in the data encryption device provided by the embodiment of the present application, the device further includes: a riddle generation unit for setting a first preset number of digits at any position on the Sudoku board before calculating the solution corresponding to the first riddle of the Sudoku to obtain a first riddle, where the first preset number is greater than or equal to 17.
[0078] Optionally, in the data encryption device provided by the embodiment of the present application, the first generation unit 602 includes: a first selection module for selecting digits from the solution and using the selected digits as candidate digits, where the candidate digits are all or part of the digits in the solution; a first combination module for combining the candidate digits according to a preset rule to obtain a key.
[0079] Optionally, in the data encryption device provided by the embodiment of the present application, the encryption unit 603 includes: a first determination module for determining the numerical values corresponding to the respective digits in the key to obtain a plurality of numerical values; a first encryption module for, when the length of the data to be encrypted is less than or equal to the length of the key, traversing the plurality of numerical values and encrypting the corresponding number of data in the data to be encrypted in sequence through each numerical value to obtain a plurality of encrypted digits, and combining the plurality of encrypted digits into encrypted data, where the corresponding number is the number indicated by the numerical value; a second encryption module for, when the length of the data to be encrypted is greater than the length of the key, traversing the plurality of numerical values multiple times and encrypting the corresponding number of data in the data to be encrypted in sequence through each numerical value until all the data in the data to be encrypted is encrypted to obtain a plurality of encrypted digits, and combining the plurality of encrypted digits into encrypted data.
[0080] Optionally, in the data encryption device provided in the embodiments of the present application, the first encryption module and the second encryption module include encryption sub-modules for encrypting corresponding amounts of data in the data to be encrypted in sequence for each value. The encryption sub-module includes: a determination sub-module for determining data with corresponding bit numbers in the data to be encrypted according to each value, obtaining corresponding amounts of data, and converting the corresponding amounts of data into decimal data; a calculation sub-module for sequentially calculating each value and the corresponding decimal data according to a preset calculation rule to obtain a plurality of encrypted numbers, where the preset calculation rule is at least one of the following: addition, subtraction, multiplication, and division.
[0081] Optionally, in the data encryption device provided in the embodiments of the present application, the encryption unit 603 further includes: a grouping module for grouping the data to be encrypted to obtain multiple groups of data; a third encryption module for encrypting each group of data separately using a key to obtain a plurality of first encrypted data; a combination module for combining the plurality of first encrypted data into encrypted data.
[0082] The above data encryption device includes a processor and a memory. The above first calculation unit 601, first generation unit 602, encryption unit 603, etc. are all stored in the memory as program units, and the processor executes the above program units stored in the memory to implement corresponding functions.
[0083] The processor contains a kernel, and the kernel retrieves the corresponding program units from the memory. One or more kernels can be set, and by adjusting the kernel parameters, the problem that in the related art, when using a stream encryption algorithm, the encryption key and the decryption key are the same, resulting in information data leakage in the case of key leakage can be solved.
[0084] The memory may include non-permanent memory in a computer-readable medium, forms such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM), and the memory includes at least one storage chip.
[0085] Figure 7 It is a schematic diagram of a data decryption device according to an embodiment of the present application, decrypting the data encrypted by the above data encryption device. As Figure 7 shown, the device includes: a receiving unit 701, a second calculation unit 702, a second generation unit 703, and a decryption unit 704.
[0086] Specifically, the receiving unit 701 is configured to receive the encrypted data and the second riddle of the sudoku sent by the sending end.
[0087] The second calculation unit 702 is configured to calculate the answer of the sudoku through the second riddle, where the second riddle is composed of the second preset amount of data in the answer.
[0088] The second generation unit 703 is configured to generate a key by using the data in the answer to the riddle.
[0089] The decryption unit 704 is configured to decrypt the encrypted data by using the key to obtain decrypted data.
[0090] The data decryption device provided in the embodiment of the present application receives, through the receiving unit 701, the encrypted data and the second riddle of the Sudoku sent by the sending end; the second calculation unit 702 calculates the answer to the Sudoku through the second riddle, where the second riddle is composed of the second preset number of data in the answer; the second generation unit 703 generates a key by using the data in the answer; the decryption unit 704 decrypts the encrypted data by using the key to obtain decrypted data, which solves the problem in the related art that when using a stream encryption algorithm, the encryption key and the decryption key are the same, resulting in information data leakage in the case of key leakage. By setting different riddles with the same answer as the encrypted data and the decrypted data, the effect of hiding the same key in the symmetric encryption algorithm is achieved, thereby improving the security of data transmission.
[0091] Optionally, in the data decryption device provided in the embodiment of the present application, the second generation unit 703 includes: a second selection module, configured to select numbers from the answer and use the selected numbers as candidate numbers, where the candidate numbers are all or part of the numbers in the answer; a second combination module, configured to combine the candidate numbers according to a preset rule to obtain a key.
[0092] Optionally, in the data decryption device provided in the embodiment of the present application, the decryption unit 704 includes: a second determination module, configured to determine the values corresponding to the respective numbers in the key to obtain a plurality of values; a first decryption module, configured to, when the length of the encrypted data is less than or equal to the length of the key, traverse the plurality of values, and calculate each decimal number in the encrypted data according to a preset calculation rule by using each value in turn to obtain a plurality of calculated data, where the preset calculation rule is at least one of the following: addition, subtraction, multiplication, and division; a second decryption module, configured to, when the length of the encrypted data is greater than the length of the key, traverse the plurality of values multiple times, and calculate each decimal number in the encrypted data according to the preset calculation rule by using each value in turn until all the data in the encrypted data is decrypted to obtain calculated data; a conversion module, configured to convert each calculated data into binary data to obtain multiple groups of binary data, and the decrypted data is composed of the multiple groups of binary data.
[0093] The above data decryption device includes a processor and a memory. The above receiving unit 701, second calculation unit 702, second generation unit 703, decryption unit 704, etc. are all stored in the memory as program units, and the corresponding functions are implemented by the processor executing the above program units stored in the memory.
[0094] The processor contains a kernel, and the kernel retrieves the corresponding program units from the memory. One or more kernels can be set, and by adjusting the kernel parameters, the problem of information data leakage caused by the same encryption and decryption keys when using the stream encryption algorithm in the related art in the case of key leakage can be solved.
[0095] The memory may include non-permanent memory in a computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM), and the memory includes at least one storage chip.
[0096] The embodiment of the present application also provides a non-volatile storage medium, and the non-volatile storage medium includes a stored program. Among them, when the program runs, it controls the device where the non-volatile storage medium is located to execute a data encryption method or a data decryption method.
[0097] The embodiment of the present application also provides an electronic device, which includes a processor and a memory; computer-readable instructions are stored in the memory, and the processor is used to run the computer-readable instructions. Among them, when the computer-readable instructions run, they execute a data encryption method or a data decryption method. The electronic device herein can be a server, a PC, a PAD, a mobile phone, etc.
[0098] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0099] The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, and the combination of the processes and / or blocks in the flowchart and / or block diagram can also be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate for implementation in the processFigure 1 means for the functions specified in one process or multiple processes and / or boxes Figure 1 or multiple boxes.
[0100] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory produce a manufactured article including an instruction means that implements the functions specified in one process Figure 1 or multiple processes and / or boxes Figure 1 or multiple boxes.
[0101] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are performed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the functions specified in one process Figure 1 or multiple processes and / or boxes Figure 1 or multiple boxes.
[0102] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.
[0103] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM), and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM). The memory is an example of computer-readable media.
[0104] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can store information by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0105] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, commodity or device comprising a series of elements not only includes those elements but also includes other elements not expressly listed, or further includes elements inherent to such process, method, commodity or device. Without further limitation, an element defined by the phrase "comprising an..." does not exclude the presence of additional identical elements in the process, method, commodity or device comprising the element.
[0106] The above are only embodiments of the present application and are not used to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
1. A method for data encryption, characterized in that, Including: Calculating the solution corresponding to the first puzzle of Sudoku, where the first puzzle is composed of a first preset number of digits on the Sudoku board, and the solution is composed of all the digits on the Sudoku board; Generating a key from the digits in the solution, and generating a second puzzle from a second preset number of digits in the solution, where the second puzzle is used to calculate the same solution as the first puzzle; Encrypting the data to be encrypted with the key to generate encrypted data, and sending the encrypted data and the second puzzle to the data receiving end, where during decryption, a key is generated from the data in the solution calculated from the second puzzle.
2. The method according to claim 1, characterized in that, Before calculating the solution corresponding to the first puzzle of Sudoku, the method further includes: Setting the first preset number of digits at any position on the Sudoku board to obtain the first puzzle, where the first preset number is greater than or equal to 17.
3. The method according to claim 1, wherein Generating a key from the digits in the solution includes: Selecting digits from the solution and using the selected digits as candidate digits, where the candidate digits are all or part of the digits in the solution; Combining the candidate digits according to a preset rule to obtain the key.
4. The method according to claim 1, wherein Encrypting the data to be encrypted with the key to generate encrypted data includes: Determining the numerical values corresponding to the respective digits in the key to obtain a plurality of numerical values; When the length of the data to be encrypted is less than or equal to the length of the key, traversing the plurality of numerical values, encrypting the corresponding number of data in the data to be encrypted with each numerical value in turn to obtain a plurality of encrypted digits, and combining the plurality of encrypted digits into the encrypted data, where the corresponding number is the number indicated by the numerical value; When the data to be encrypted is greater than the length of the key, traversing the plurality of numerical values multiple times, encrypting the corresponding number of data in the data to be encrypted with each numerical value in turn until all the data in the data to be encrypted is encrypted, obtaining a plurality of encrypted digits, and combining the plurality of encrypted digits into the encrypted data.
5. The method according to claim 1, wherein Encrypting the corresponding number of data in the data to be encrypted with each numerical value in turn to obtain a plurality of encrypted digits includes: Determining the data with the corresponding number of bits in the data to be encrypted according to each numerical value to obtain the corresponding number of data, and converting the corresponding number of data into decimal data; Calculating each numerical value and the corresponding decimal data according to a preset calculation rule in turn to obtain a plurality of encrypted digits, where the preset calculation rule is at least one of the following: addition, subtraction, multiplication, and division.
6. The method according to claim 1, wherein Encrypting the data to be encrypted with the key to generate encrypted data includes: Grouping the data to be encrypted to obtain multiple groups of data; Using the key to encrypt each group of data respectively to obtain a plurality of first encrypted data; Combining the plurality of first encrypted data into the encrypted data.
7. A method for data decryption, characterized in that, Decrypting the data encrypted by the data encryption method according to any one of claims 1 to 6 includes: Receiving the encrypted data and the second puzzle of Sudoku sent by the sending end; Calculate the solution of the Sudoku through the second riddle, where the second riddle consists of a second preset number of data in the solution; Generate a key through the data in the solution; Decrypt the encrypted data with the key to obtain decrypted data.
8. The method according to claim 7, wherein Generating a key through the numbers in the solution includes: Select numbers from the solution and use the selected numbers as candidate numbers, where the candidate numbers are all or part of the numbers in the solution; Combine the candidate numbers according to a preset rule to obtain the key.
9. The method according to claim 7, characterized in that Decrypting the encrypted data with the key to obtain decrypted data includes: Determine the numerical values corresponding to each number in the key to obtain a plurality of numerical values; When the length of the encrypted data is less than or equal to the length of the key, traverse the plurality of numerical values, and calculate each decimal digit in the encrypted data in turn according to a preset calculation rule by each numerical value to obtain a plurality of calculated data, and the preset calculation rule is at least one of the following: addition, subtraction, multiplication, and division; When the length of the encrypted data is greater than the length of the key, traverse the plurality of numerical values multiple times, and calculate each decimal digit in the encrypted data in turn according to a preset calculation rule by each numerical value until all the data in the encrypted data are decrypted to obtain calculated data; Convert each of the calculated data into binary data to obtain multiple sets of binary data, and the decrypted data is composed of the multiple sets of binary data.
10. A data encryption device, characterized in that, Including: A first calculation unit for calculating the solution corresponding to the first riddle of the Sudoku, where the first riddle consists of a first preset number of numbers on the Sudoku board, and the solution consists of all the numbers on the Sudoku board; A first generation unit for generating a key through the numbers in the solution and generating a second riddle through a second preset number of numbers in the solution, where the same solution as the first riddle is obtained by calculating the second riddle; An encryption unit for encrypting the data to be encrypted with the key to generate encrypted data, and sending the encrypted data and the second riddle to a data receiving end, where, during decryption, a key is generated through the data in the solution calculated by the second riddle.
11. A data decryption device, characterized in that, Decrypt the encrypted data of the data encryption device according to claim 10, including: A receiving unit for receiving the encrypted data sent by the sending end and the second riddle of the Sudoku; A second calculation unit for calculating the solution of the Sudoku through the second riddle, where the second riddle consists of a second preset number of data in the solution; A second generation unit for generating a key through the data in the solution; A decryption unit for decrypting the encrypted data with the key to obtain decrypted data.
Citation Information
Patent Citations
Power data encryption method and device and terminal
CN113127911A