An encryption and decryption method
By performing multi-layered encryption on the file, including file packaging, random number generation, and authorization code processing, the problem of easy cracking of existing encryption technologies is solved, achieving a high level of security and self-healing encryption effect.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANJING RES INST OF ELECTRONICS TECH
- Filing Date
- 2022-10-16
- Publication Date
- 2026-07-03
AI Technical Summary
Existing encryption technologies are relatively insecure and easy to crack, failing to effectively protect the core data and files of enterprises or countries, especially vulnerable to leakage during illegal copying and cyberattacks.
A complex encryption method is employed, which involves packaging the file to be encrypted into a .rar format and combining multiple byte integers, random numbers Rndout and Rndout1, and the license code Licence for multi-layer encryption. This includes file length transformation, string length and ASCII code processing to ensure that each byte is randomly encrypted. Reference data is added to the beginning and end of the file to achieve self-healing.
It achieves high-security encryption for files of any format, increases file size by a small number of bytes, and the encryption algorithm is difficult to crack, preventing illegal copying and improving data and file security.
Smart Images

Figure CN115941162B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of encryption technology, and in particular relates to a method for encrypting and decrypting files and data. Background Technology
[0002] Modern society belongs to the era of big data. Due to the development of the Internet in recent years, more and more data and files will leave traces and be recorded online. The security of data and files is particularly important. Once these data and files are leaked, they will pose a major security threat to enterprises and even the country. Data and file encryption can solve this problem very well.
[0003] Existing encryption technologies primarily utilize keys for encryption. Depending on the file format, the encryption algorithm is generally fixed, making these encryption methods relatively simple, easy to crack, and thus insecure. Individuals and businesses alike should strengthen the protection of core data and documents related to their operations and even national security, preventing unauthorized access by irrelevant individuals or organizations. Data and document leaks typically occur through illegal copying or cyberattacks; therefore, preventing illegal copying and cyberattacks through technical means is crucial for ensuring data and document security. Summary of the Invention
[0004] To overcome the shortcomings of existing technologies, a file and data encryption and decryption method is proposed. The encrypted file length = file length to be encrypted + two-byte integer Num + four-byte long integer Rndout + four-byte long integer Rndout1 + the first and second lines of the license code (Licence) + two-byte length of the first line of the license code + two-byte length of the second line of the license code + four-byte number of blocks N. The specific steps include:
[0005] a) Package the files to be encrypted into a compressed file in .rar format;
[0006] b) Generate encrypted files;
[0007] c) Store the two-byte integer word Num;
[0008] d) Store the four-byte long integer word Rndout;
[0009] e) Store the four-byte long integer word Rndout1;
[0010] f) Encrypt and store the contents of the file to be encrypted that are multiples of the integer word Num: Read two bytes of the file to be encrypted, subtract them from the long integer word Rndout, and determine whether the result is less than -32768. If so, add 65536 and store two bytes, then subtract 1 from the long integer word Rndout. If not, store two bytes directly and then subtract 1 from the long integer word Rndout.
[0011] g) Processing the length transformation of the first line of the License string: Take the length of the first line of the License string, subtract the long integer Rndout1, and determine whether the result is less than 0. If it is, add 256 and then invert the result, and store it in bytes. If not, directly invert the result and store it in bytes.
[0012] h) Subtract 1 from the long integer Rndout1;
[0013] i) Processing the first line of the License string: Take the ASCII code of the character in the first line of the License string, subtract the long integer Rndout1, and determine if the result is less than 0. If it is, add 256 and then invert the result, and store it in bytes. If not, directly invert the result and store it in bytes, and subtract 1 from the long integer Rndout1.
[0014] j) Restoration of the longest integer Rndout1;
[0015] k) Processing the length transformation of the second line of the License string: Take the length of the second line of the License string, subtract the long integer Rndout1, and determine whether the result is less than 0. If it is, add 256 and then invert the result, and store it in bytes. If not, directly invert the result and store it in bytes.
[0016] l) Subtract 1 from the longest integer Rndout1;
[0017] m) Processing the second line of the License string: Take the ASCII code of the character in the second line of the License string, subtract the long integer Rndout1, and determine if the result is less than 0. If it is, add 256 and then invert the result, and store it in bytes. If not, directly invert the result and store it in bytes, and subtract 1 from the long integer Rndout1.
[0018] n) Restoration of the longest integer Rndout1;
[0019] o) Processing the remaining content of the encrypted file: Read one byte, subtract the long integer Rndout1, and determine if the result is less than 0. If it is, add 256, invert the result, and store it in the byte. If not, invert the result and store it in the byte, and subtract 1 from the long integer Rndout1.
[0020] The file encryption is now complete.
[0021] The decryption process is the inverse operation of the encryption process.
[0022] Furthermore, during the encryption process, it is determined whether the values of the long integer Rndout and the long integer Rndout1 are 1. If they are 1, the process is restored; otherwise, the values are decremented by 1.
[0023] Furthermore, the encrypted file header consists of 10 auxiliary bytes containing reference data for decryption, the file end contains the file block number N, the middle part contains the license information, and the remaining parts are the encrypted file data, specifically composed of the following:
[0024] a) Integer Num: Indicates the file block size;
[0025] b) Long integer word Rndout, a random number from 0 to 999: used as the initial factor for file encryption transformation;
[0026] c) Long integer Rndout1, a random number from 0 to 99: used as the initial factor for the Licence encryption transformation;
[0027] d) Encrypt file block 1;
[0028]
[0029] e) The encrypted file is divided into N / 2 blocks, where N is an even number or (N-1) / 2, where N is an odd number;
[0030] f) Results of the Licence transformation;
[0031] g) Encrypt the file into blocks N / 2+1, where N is an even number or (N-1) / 2+1, where N is an odd number;
[0032]
[0033] h) Encrypt file blocks N;
[0034] i) The remaining content of the encrypted file after it has been divided into N blocks;
[0035] j) The length of the first line of the License is two bytes;
[0036] k) The length of the second line of the License is two bytes;
[0037] l) Number of blocks N: Four bytes, N = (length of the file to be encrypted / Num) integer part.
[0038] Furthermore, the rules for generating the license code are as follows:
[0039] Password rules: Combination of letters, symbols and numbers, case sensitive, maximum length 10 characters;
[0040] The license consists of two lines. The first line consists of three parts: the password processing result, the password length, and a 10-digit random number.
[0041] The password processing result consists of the length of the processed string (number of characters), the length of the processed string, and the password processing result itself. The processing result for the i-th password character is as follows:
[0042]
[0043]
[0044] The beneficial effects of this invention are as follows:
[0045] 1) For files of any format: documents, data, images, audio and video, etc. can be encrypted for storage, transmission and decryption.
[0046] 2) The encrypted file adds only a small number of bytes, with no excessive redundancy, and is roughly the same size as the file to be encrypted.
[0047] 3) The encryption algorithm performs random encryption operations on each byte of the original file, resulting in high confidentiality.
[0048] 4) The encryption and decryption programs are self-repairing, cannot be copied at will, and have high security. Attached Figure Description
[0049] Figure 1 Flowchart for authorization, encryption, and decryption.
[0050] Figure 2 This is a diagram illustrating the License rules.
[0051] Figure 3 This is a schematic diagram of the encrypted file structure.
[0052] Figure 4 This is a schematic diagram of the encryption process.
[0053] Figure 5 This is a schematic diagram illustrating the length transformation of the first line of the License string.
[0054] Figure 6 This is a diagram illustrating the transformation and processing of the first line of the License string.
[0055] Figure 7 This is a schematic diagram illustrating the length transformation of the second line of the License string.
[0056] Figure 8 This is a diagram illustrating the transformation and processing of the second line of the License string.
[0057] Figure 9A diagram illustrating the encryption process for the remaining file content.
[0058] Figure 10 A diagram illustrating variable handling. Detailed Implementation
[0059] The technical solutions in the embodiments of the present invention will be clearly and completely described below. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0060] like Figure 1 As shown, when the encryption and decryption software is run for the first time, it first grants authorization by entering a password: a maximum of 10 characters, a combination of letters and numbers. Then the software performs self-correction, sets the authorization license, and can begin encrypting files. If it is not the first time running, it checks whether the software is an illegal copy. If so, it sets an illegal copy flag and permanently prohibits the software from running. If it is legitimate software, it enters the password for verification.
[0061] like Figure 2 The license generation rule shown assumes the input password is Cwd1963, and the generated 10-digit random number is 2368714537. The password length is 7.
[0062] License generation: If the ASCII code of the password is 67, 119, 100, 49, 57, 54, 51, then:
[0063] 1. (67+7+2) 4 =33362176, resulting in 18133362176.
[0064] 2. (119+7+3) 4 =268435456, resulting in 191268435456.
[0065] 3. (100+7+6) 4 =163047361, resulting in 191163047361.
[0066] 4. (49+7+8) 5 =1073741824, resulting in 21001073741824.
[0067] 5. (57+7+7) 5 =1804229351, resulting in 21001804229351.
[0068] 6. (54+7+1) 5=916132832, resulting in 190916132832.
[0069] 7. (51+7+4) 5 =916132832, resulting in 190916132832.
[0070] Based on the calculated data, we can conclude that:
[0071] The first line of Licence.dat is: 18133362176191268435456191163047361210010737418242100180422935119091613283219091613283272368714537.
[0072] C drive serial number: 1ACA681E = 449472542, 449472542× 4537 =2039256923054, then the second line of License.dat is: 2039256923054.
[0073] like Figure 3 The encrypted file structure shown has a header of 10 auxiliary bytes containing reference data for decryption, a file block number at the end, a license file information in the middle, and the remaining parts are the encrypted file data.
[0074] Assuming Num = 5000, and RndOut = 47 and RndOut1 = 80 are randomly generated, and the size of the file to be encrypted is 123456789 bytes, the structure of the encrypted file is shown in the table below.
[0075]
[0076] like Figure 4-10 The encryption algorithm flow is shown below.
[0077] a) Package the files (one or more) to be encrypted into a compressed file in .rar format.
[0078] b) Generate encrypted files.
[0079] c) Store the integer Num: assume it is 5000 (two bytes).
[0080] d) Store in a long integer word Rndout: Assume it is 47 (four bytes) (a random number from 0 to 999).
[0081] e) Store the long integer Rndout1: Assume it is 80 (four bytes) (a random number from 0 to 99).
[0082] f) Encrypt and store the contents of the file whose length is a multiple of Num using the following method.
[0083] g) Processing the length transformation of the first line of the License string.
[0084] h)Rndout1-1.
[0085] i) Transformation and processing of the first line of the License string.
[0086] j)Rndout1 restores.
[0087] k) The length of the second line of the License string is transformed.
[0088] l)Rndout1-1.
[0089] m)Licence The second line of the string is transformed.
[0090] n)Rndout1 restores.
[0091] o) Methods for encrypting the remaining file content.
[0092] p) Handling of Rndout1-1 and Rndout-1 variables.
[0093] The decryption process is the inverse operation of the encryption process.
[0094] This invention is not limited to the specific embodiments described above, and various modifications and variations are possible. Any modifications, equivalent substitutions, or improvements made to the above embodiments based on the technical essence of this invention should be included within the scope of protection of this invention.
Claims
1. An encryption method, characterized in that: The length of the encrypted file = the length of the file to be encrypted + two bytes of integer Num + four bytes of long integer Rndout + four bytes of long integer Rndout1 + the first and second lines of the license code + two bytes of the length of the first line of the license + two bytes of the length of the second line of the license + four bytes of the number of blocks N. Specifically, this includes the following steps: a) Package the files to be encrypted into a compressed file in .rar format; b) Generate an encrypted file; c) Store the two-byte integer word Num; d) Store the four-byte integer word Rndout; e) Store the four-byte long integer word Rndout1; f) Encrypt and store the contents of the file to be encrypted that are multiples of the integer word Num: Read two bytes of the file to be encrypted, subtract them from the long integer word Rndout, and determine whether the result is less than -32768. If so, add 65536 and store two bytes, then subtract 1 from the long integer word Rndout. If not, store two bytes directly and then subtract 1 from the long integer word Rndout. g) Processing the length transformation of the first line of the License string: Take the length of the first line of the License string, subtract the long integer Rndout1, and determine whether the result is less than 0. If it is, add 256 and then invert the result, and store it in bytes. If not, directly invert the result and store it in bytes. h) Subtract 1 from the long integer Rndout1; i) Processing the first line of the License string: Take the ASCII code of the character in the first line of the License string, subtract the long integer Rndout1, and determine if the result is less than 0. If it is, add 256 and then invert the result, and store it in bytes. If not, directly invert the result and store it in bytes, and subtract 1 from the long integer Rndout1. j) After all characters in the first line of the License have been transformed, restore Rndout1; k) Processing the length transformation of the second line of the License string: Take the length of the second line of the License string, subtract the long integer Rndout1, and determine whether the result is less than 0. If it is, add 256 and then invert the result, and store it in bytes. If not, directly invert the result and store it in bytes. l) Subtract 1 from the longest integer Rndout1; m) Processing the second line of the License string: Take the ASCII code of the character in the second line of the License string, subtract the long integer Rndout1, and determine if the result is less than 0. If it is, add 256 and then invert the result, and store it in bytes. If not, directly invert the result and store it in bytes, and subtract 1 from the long integer Rndout1. After all characters in the second line of the License have been transformed, restore Rndout1; o) Processing the remaining content of the encrypted file: Read one byte, subtract the long integer Rndout1, and determine if the result is less than 0. If it is, add 256, invert the result, and store it in the byte. If not, invert the result and store it in the byte, and subtract 1 from the long integer Rndout1. The file encryption is now complete.
2. The encryption method according to claim 1, characterized in that: During the encryption process, it is determined whether the values of the long integer Rndout and the long integer Rndout1 are 1. If they are 1, the encryption is restored; otherwise, the values are decremented by 1.
3. The encryption method according to claim 1, characterized in that: The encrypted file header consists of 10 auxiliary bytes containing reference data for decryption. The file end indicates the file block number N. The middle portion contains the license information, and the remaining portion is the encrypted file data, specifically composed of the following parts: a) Integer Num: Indicates the file block size; b) Long integer word Rndout, a random number from 0 to 999: used as the initial factor for file encryption transformation; c) A long integer word Rndout1, a random number from 0 to 99: used as an initial factor for the Licence encryption transformation; d) Encrypt file block 1; ┆ e) The encrypted file is divided into N / 2 blocks, where N is an even number or (N-1) / 2, where N is an odd number; f) Results of the Licence transformation; g) Encrypt the file into blocks N / 2+1, where N is an even number or (N-1) / 2+1, where N is an odd number; ┆ h) Encrypt file blocks N; i) The remaining content of the encrypted file after it has been divided into N blocks; j) Length of the first line of the License: two bytes; k) The length of the second line of the License is two bytes; l) Number of blocks N: Four bytes, N = (length of the file to be encrypted / Num) integer part.
4. The encryption method according to claim 1, characterized in that: The rules for generating the license code are as follows: Password rules: Combination of letters, symbols and numbers, case sensitive, maximum length 10 characters; The license consists of two lines. The first line consists of three parts: the password processing result, the password length, and a 10-digit random number. The password processing result consists of the length of the processed string (in bytes), the length of the processed string, and the password processing result itself; The processing results for each password character are as follows:
5. A decryption method, characterized in that: Used to decrypt the file encrypted by the method described in claim 1, wherein the decryption process is the inverse operation of the encryption process.