Digital encryption and decryption method based on confusion algorithm
By using a digital encryption and decryption method based on obfuscation algorithms, the problem of plaintext risk in data storage and low efficiency of existing encryption methods is solved. This method achieves reversible encryption and fast data processing, reduces server resource consumption, and supports seamless transformation of old systems.
Patent Information
- Application Number
- CN202311179861.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-13
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-09-13
Smart Images

Figure CN117112228B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of data encryption and decryption technology, and relates to a digital encryption and decryption method based on an obfuscation algorithm. Background Technology
[0002] Currently, data storage in databases generally uses plaintext storage, but plaintext storage has certain risks. For example, if key digital information such as amounts, mobile phone numbers, and ID card numbers is compromised, it can easily lead to the leakage of a large amount of critical data.
[0003] There are several common methods for encrypting and storing data. The first is MD5 encryption, but MD5 is a lossy encryption method and is irreversible. The second is Base64 encryption. Base64 encryption results in a long ciphertext, and Base64 has low transcoding efficiency, consumes a lot of network bandwidth, and requires a large amount of server storage. The third is SHA1 encryption. SHA1 is based on MD5 and is more secure than MD5, but it results in a long encrypted data length and slow processing speed. The fourth is RSA encryption. Its encryption and decryption operations involve complex exponential operations, resulting in a very slow processing speed.
[0004] The above encryption methods result in excessively long text that must be stored as text, consuming significant server resources. Furthermore, converting plaintext to encrypted storage requires changing database field types, which is problematic when modifying older systems as the database structure cannot be altered, thus hindering data access. Summary of the Invention
[0005] To address the shortcomings of existing technologies, this invention aims to provide a digital encryption and decryption method based on obfuscation algorithms, thereby simplifying data storage and reducing server usage.
[0006] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0007] A digital encryption and decryption method based on a confusion algorithm, the method comprising a digital encryption process and a digital decryption process;
[0008] The digital encryption process includes the following steps performed sequentially:
[0009] a1) Convert each plaintext number into its corresponding ASCII code and concatenate them into the first string;
[0010] a2) Convert the concatenated first string into a first byte array to obtain the binary information corresponding to the first byte array;
[0011] a3) Generate the first checksum by performing CRC8 verification based on the binary information corresponding to the first byte array;
[0012] a4) Concatenate the first checksum to the first string to form the first mixed string;
[0013] a5) Obfuscate the first mixed string using an obfuscation algorithm to obtain the first obfuscated string;
[0014] a6) Encrypt the first obfuscated string and the key using an encryption function to generate ciphertext. The encryption calculation formula in the encryption function is:
[0015] a⊕b=c, where a is the first obfuscation string, b is the key, and c is the ciphertext;
[0016] a7) Convert the ciphertext into ciphertext digital information for storage and transmission;
[0017] The digital decryption process includes the following steps performed sequentially:
[0018] b1) Perform an XOR operation on the ciphertext digital information in step a7) and the key used in the encryption process using the decryption function to obtain the second obfuscated string;
[0019] b2) Perform reverse obfuscation on the second obfuscated string to obtain the second mixed string;
[0020] b3) Decompose the second mixed string to obtain the second string;
[0021] b4) Convert the second string into a second byte array to obtain the binary information corresponding to the second byte array;
[0022] b5) Perform CRC8 verification based on the binary information corresponding to the second byte array to generate the second check code;
[0023] b6) Compare the first checksum and the second checksum to verify the validity of the second byte array;
[0024] If verification fails, an empty value is returned, ending the decryption process.
[0025] If the verification is successful, return the second byte array and continue to execute step b7);
[0026] b7) Convert the second byte array into plaintext numbers using a number conversion function.
[0027] As a limitation, the polynomial used for CRC8 verification in step a3) is x8+x5+x4+1.
[0028] As a second limitation, the key used in step a6) is arbitrarily set by the user and can be obtained in any step prior to step a6).
[0029] As a third limitation, the specific method for the confusion calculation in step a5) is as follows:
[0030] a51) Subtract the ASCII code value 48 from the ASCII code value of each character in the first mixed string to obtain the displacement value of each character in the first mixed string;
[0031] a52) Select any number N from 0 to 9. For each character, subtract the corresponding shift value of the character from the number N to obtain the confusion value of the character.
[0032] a53) Concatenate the obfuscation values corresponding to each character in sequence to obtain the first obfuscated string.
[0033] As a fourth limitation, the method for inverse confusion calculation in step b2) is as follows:
[0034] b21) Decompose the first obfuscated string into the obfuscation value corresponding to each character;
[0035] b22) Subtract the confusion value corresponding to each character from the number N selected in step a52) to obtain the displacement value corresponding to each character;
[0036] b23) Add the ASCII code value 48 to the displacement value corresponding to each character obtained in step b22), and concatenate them to obtain the first mixed string.
[0037] By adopting the above-described technical solution, the beneficial effects achieved by this invention compared to the prior art are as follows:
[0038] (1) The present invention obtains a set of encrypted numbers through confusion operation and XOR encryption operation. After encryption, the data can be reversed and restored. It can store encrypted numbers that need to be kept confidential. At the same time, the method of the present invention has fast data processing speed, streamlines data storage, and reduces server usage.
[0039] (2) The method of the present invention is convenient for other programs to be ported and accessed. By using the encryption algorithm block of the present invention, the encrypted value or the decrypted value can be returned.
[0040] In summary, the data encrypted in this invention can be reversed and restored, simplifying data storage, reducing server usage, and can also be called by other programs. Attached Figure Description
[0041] The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0042] Figure 1 This is a flowchart of a digital encryption method according to an embodiment of the present invention;
[0043] Figure 2This is a flowchart of the digital decryption method according to an embodiment of the present invention. Detailed Implementation
[0044] To better explain and facilitate understanding of the present invention, the preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings and specific implementation methods.
[0045] Example: Digital Encryption and Decryption Method Based on Obfuscation Algorithm
[0046] like Figure 1 As shown, this embodiment provides a digital encryption and decryption method based on a confusion algorithm. The method includes a digital encryption process and a digital decryption process. In this embodiment, the number 7326.19 is input for encryption and decryption, and the key is set to 14826.
[0047] The digital encryption process includes the following steps performed sequentially:
[0048] a1) Convert the plaintext numbers one by one into their corresponding ASCII codes using the Str_to_ASCII function, and then concatenate them into the first string: 555150544957.
[0049] a2) Convert the concatenated first string into a first byte array using the GetBytes function to obtain the binary information corresponding to the first byte array. The resulting first byte array is:
[0050] {53,53,53,49,53,48,53,52,52,57,53,55}.
[0051] a3) Based on the binary information corresponding to the first byte array, the CRC8 checksum generation function is used to generate the first checksum. The polynomial of the CRC8 checksum is x8+x5+x4+1, and the first checksum is 14.
[0052] a4) Use the Mixed_String function to append the first checksum to the first string to form the first mixed string: 55515054495714.
[0053] a5) The first mixed string is obfuscated using the obfuscation algorithm function Confusion to obtain the first obfuscated string: 267380.
[0054] The specific method for obfuscation calculation is as follows:
[0055] a51) Subtract the ASCII code value of the number zero (48) from the ASCII code value of each character in the first mixed string to obtain the displacement value of each character in the first mixed string.
[0056] (a52) Select any number N from 0 to 9. For each character, subtract the corresponding shift value of the character from the number N to obtain the confusion value of the character. In this implementation, N = 9.
[0057] a53) Concatenate the obfuscation values corresponding to each character in sequence to obtain the first obfuscated string.
[0058] a6) Encrypt the first obfuscated string and the key using the encryption function String_Encryption to generate ciphertext digital information. The encryption calculation formula in the encryption function is as follows:
[0059] a⊕b=c, where a is the first obfuscated string, b is the key, and c is the ciphertext.
[0060] a7) Convert the ciphertext into ciphertext numeric information for storage and transmission using the ASCII_to_Str function: 2738.22.
[0061] The digital decryption process includes the following steps performed sequentially:
[0062] b1) Perform an XOR operation on the ciphertext digital information in step a7) and the key 14826 used in the encryption process using the Code_decrypt function to obtain the second obfuscated string: 267380.
[0063] b2) Perform reverse obfuscation calculation and parsing on the second obfuscated string to obtain the second mixed string: 55515054495714.
[0064] The method for reverse confusion calculation is as follows:
[0065] b21) Decompose the first obfuscated string into the obfuscation value corresponding to each character.
[0066] b22) Subtract the confusion value corresponding to each character from the number 9 selected in step a52) to obtain the displacement value corresponding to each character.
[0067] b23) Add the ASCII code value 48 to the displacement value corresponding to each character obtained in step b22), and concatenate them to obtain the second mixed string.
[0068] b3) Decompose the second mixed string to get the second string: 555150544957.
[0069] b4) Convert the second string into a second byte array to obtain the binary information corresponding to the second byte array: the second byte array is: {53,53,53,49,53,48,53,52,52,57,53,55}.
[0070] b5) Perform CRC8 verification based on the binary information corresponding to the second byte array to generate the second check code 14.
[0071] b6) Compare the first checksum and the second checksum. If the second checksum matches the first checksum, and the first byte array matches the second byte array, the verification is successful. Return the second byte array.
[0072] {53,53,53,49,53,48,53,52,52,57,53,55}, continue with step b7).
[0073] b7) Convert the second byte array {53,53,53,49,53,48,53,52,52,57,53,55} into the plaintext number 7326.19 using a number conversion function.
[0074] The functions involved in this embodiment include:
[0075] The function to convert plaintext numbers to ASCII strings is: Str_to_ASCII(string str), where string str is the plaintext number. After the function is executed, it returns the ASCII code of type string. This function searches for the ASCII code corresponding to each number one by one and concatenates the search results to output a string.
[0076] The function to convert plaintext strings to byte arrays is GetBytes(string ascii), where string ascii is a string. After the function is executed, it returns binary information as a byte[]. This function converts ASCII codes into byte arrays.
[0077] The CRC8 checksum generation function is: CRC8(byte[]code), where byte[]code is binary ASCII code information, and the function returns a two-bit checksum value after execution.
[0078] The Mixed String function is: Mixed_String(string str, string code), where string str is an ASCII string and string code is a checksum string. After execution, the function returns a mixed string of type string. This function concatenates the ASCII string and the checksum.
[0079] The obfuscation algorithm function is: Confusion(string char), where string char is the string to be obfuscated, and the function returns the obfuscated string after execution.
[0080] The encryption function is `String_Encryption(string Code)`, where `string Code` is the obfuscated string to be encrypted. After execution, the function returns the ASCII code of type `string`. The encryption function uses an XOR operation. Encryption is achieved by XORing the input first obfuscated string and the key.
[0081] The decryption function is `Code_decrypt(string code)`, where `string code` is the ciphertext. The function returns an obfuscated string after execution. The decryption function uses an XOR operation. The input ciphertext and key are XORed together to achieve decryption.
[0082] The function to convert numbers is ASCII_to_Str(string ASC), where string ASC is the ASCII code corresponding to the obfuscated string. After the function is executed, it returns a string-type number. This function converts ASCII to decimal numbers.
Claims
1. A digital encryption and decryption method based on a confusion algorithm, characterized in that, The method includes a digital encryption process and a digital decryption process; The digital encryption process includes the following steps performed sequentially: a1) Convert each plaintext number into its corresponding ASCII code and concatenate them into the first string; a2) Convert the concatenated first string into a first byte array to obtain the binary information corresponding to the first byte array; a3) Generate the first checksum by performing CRC8 verification based on the binary information corresponding to the first byte array; a4) Concatenate the first checksum to the first string to form the first mixed string; a5) Obfuscate the first mixed string using an obfuscation algorithm to obtain the first obfuscated string; a6) Encrypt the first obfuscated string and the key using an encryption function to generate ciphertext. The encryption calculation formula in the encryption function is: a⊕b=c, where a is the first obfuscation string, b is the key, and c is the ciphertext; a7) Convert the ciphertext into ciphertext digital information for storage and transmission; The digital decryption process includes the following steps performed sequentially: b1) Perform an XOR operation on the ciphertext digital information in step a7) and the key used in the encryption process using the decryption function to obtain the second obfuscated string; b2) Perform reverse obfuscation on the second obfuscated string to obtain the second mixed string; b3) Decompose the second mixed string to obtain the second string; b4) Convert the second string into a second byte array to obtain the binary information corresponding to the second byte array; b5) Perform CRC8 verification based on the binary information corresponding to the second byte array to generate the second check code; b6) Compare the first checksum and the second checksum to verify the validity of the second byte array; If verification fails, an empty value is returned, ending the decryption process. If the verification is successful, return the second byte array and continue to execute step b7); b7) Convert the second byte array into plaintext numbers using a number conversion function.
2. The digital encryption and decryption method based on the obfuscation algorithm according to claim 1, characterized in that, The polynomial used for CRC8 verification in step a3) is x8+x5+x4+1.
3. The digital encryption and decryption method based on an obfuscation algorithm according to claim 1 or 2, characterized in that, The key used in step a6) is arbitrarily set by the user and can be obtained in any step before step a6).
4. The digital encryption and decryption method based on the obfuscation algorithm according to claim 1 or 2, characterized in that, The specific method for confusion calculation in step a5) is as follows: a51) Subtract the ASCII code value 48 from the ASCII code value of each character in the first mixed string to obtain the displacement value of each character in the first mixed string; a52) Select any number N from 0 to 9. For each character, subtract the corresponding shift value of the character from the number N to obtain the confusion value of the character. a53) Concatenate the obfuscation values corresponding to each character in sequence to obtain the first obfuscated string.
5. The digital encryption and decryption method based on an obfuscation algorithm according to claim 1 or 2, characterized in that, The method for inverse confusion calculation in step b2) is as follows: b21) Decompose the first obfuscated string into the obfuscation value corresponding to each character; b22) Subtract the confusion value corresponding to each character from the number N selected in step a52) to obtain the displacement value corresponding to each character; b23) Add the ASCII code value 48 to the displacement value corresponding to each character obtained in step b22), and concatenate them to obtain the second mixed string.
Citation Information
Patent Citations
Copying and snapshot combined Windows system protection method
CN101777018A
Digital ID obfuscation method and device, and obfuscated digital ID verification method and device
CN110334528A
