Encryption method, decryption method, and related devices
By generating encryption/decryption obfuscation replacement index bits through modulo operation of the index bit and key string length, the complexity of encryption and decryption in existing technologies is solved, achieving efficient equal-length encryption and decryption, and adapting to the encryption and decryption needs of digital or non-digital data.
Patent Information
- Application Number
- CN202410595796.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-14
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2044-05-14
AI Technical Summary
When using the AES-128 encryption and decryption algorithm on an FPGA platform, existing equal-length encryption schemes rely on the length of the input data, padding, and high and low bits from the previous encryption/decryption to concatenate and cover them, resulting in complex encryption and decryption and low efficiency.
By obtaining the modulo operation result of the index bits of the data to be encrypted/decrypted and the length of the key string, the replacement index bits for encryption/decryption are generated. The characters in the basic string are used to generate ciphertext/plaintext data of equal length, which can adapt to the encryption and decryption needs of digital or non-digital data.
It reduces the computational complexity of fixed-length encryption, improves encryption and decryption speed, and adapts to encryption and decryption needs in various special occasions, thus enhancing practicality.
Smart Images

Figure CN118802112B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of IT infrastructure, and more particularly to an encryption method, a decryption method, and related equipment. Background Technology
[0002] In sensitive data encryption scenarios, the encrypted ciphertext must be the same length as the plaintext, such as for sensitive numeric data (e.g., ID cards, phone numbers). Existing equal-length encryption schemes use FPGA platforms and CBC mode that supports the AES-128 encryption and decryption algorithm. During implementation, this scheme relies on the length of the input data, padding, and high-low bit concatenation from the previous encryption (ciphertext) / decryption (plaintext) to achieve the final equal-length plaintext and ciphertext data. This is essentially a re-encapsulation of the AES open-source algorithm, making encryption and decryption complex and impacting efficiency. Summary of the Invention
[0003] To address at least one technical problem in the prior art, this disclosure provides an encryption method, a decryption method, and related equipment.
[0004] According to a first aspect of this disclosure, an encryption method is provided, comprising:
[0005] Obtain the first index of each character in the base string and the second index in the data to be encrypted;
[0006] Obtain the modulo operation result of the relevant function value of the second index bit and the length of the key string, and use it as the third index bit;
[0007] Based on the first index position and the character in the key string corresponding to the third index position, obtain the replacement index position for encryption and obfuscation of each character of the data to be encrypted;
[0008] The ciphertext data of the data to be encrypted is generated based on the character at the replacement index position in the base string.
[0009] Optionally, before obtaining the first index of each character in the base string and the second index in the data to be encrypted, the method further includes:
[0010] Obtain the data to be encrypted;
[0011] Determine whether the data to be encrypted is digital data;
[0012] If the data to be encrypted is numeric data, then a basic numeric string is used as the base string; otherwise, a basic mixed string is used as the base string.
[0013] Optionally, obtaining the modulo operation result of the relevant function value of the second index bit and the length of the key string as the third index bit includes:
[0014] The modulo operation result is obtained by using the equivalent function value as the relevant function value of the second index bit, and then used as the third index bit.
[0015] Optionally, obtaining the replacement index for encryption and obfuscation of each character in the data to be encrypted based on the first index bit and the character in the key string corresponding to the third index bit includes:
[0016] Based on the character corresponding to the third index position in the key string, obtain the fourth index position of the corresponding character in the basic mixed string;
[0017] The first index bit is encrypted and obfuscated using the fourth index bit to obtain the replacement index bit for the encryption and obfuscation of each character of the data to be encrypted.
[0018] According to a second aspect of this disclosure, a decryption method includes:
[0019] Obtain the first index of each character in the base string and the second index in the data to be decrypted;
[0020] Obtain the modulo operation result of the relevant function value of the second index bit and the length of the key string, and use it as the third index bit;
[0021] Based on the first index position and the character in the key string corresponding to the third index position, obtain the replacement index position for decryption obfuscation of each character in the data to be decrypted;
[0022] The plaintext data of the data to be decrypted is generated based on the character at the replacement index in the base string.
[0023] Optionally, before obtaining the first index of each character in the base string and the second index in the data to be decrypted, the method further includes:
[0024] Obtain the data to be decrypted;
[0025] Determine whether the data to be decrypted is digital data;
[0026] If the data to be decrypted is numeric data, then a basic numeric string is used as the base string; otherwise, a basic mixed string is used as the base string.
[0027] or,
[0028] The step of obtaining the modulo operation result of the relevant function value of the second index bit and the key string length, and using it as the third index bit, includes:
[0029] Using the equivalent function value as the relevant function value of the second index bit, the result of the modulo operation is obtained and used as the third index bit;
[0030] or,
[0031] The step of obtaining the replacement index for encryption and obfuscation of each character in the data to be decrypted based on the first index bit and the character in the key string corresponding to the third index bit includes:
[0032] Based on the character corresponding to the third index position in the key string, obtain the fourth index position of the corresponding character in the basic mixed string;
[0033] The first index bit is encrypted and obfuscated using the fourth index bit to obtain the replacement index bit for the encryption and obfuscation of each character of the data to be decrypted.
[0034] According to a third aspect of this disclosure, an encryption device includes:
[0035] The first acquisition module is used to acquire the first index position of each character in the base string and the second index position in the data to be encrypted;
[0036] The second acquisition module is used to acquire the modulo operation result of the relevant function value of the second index bit and the length of the key string, and use it as the third index bit;
[0037] The third acquisition module is used to acquire the replacement index of encryption and obfuscation for each character of the data to be encrypted based on the first index and the character in the key string corresponding to the third index.
[0038] The ciphertext data generation module is used to generate ciphertext data of the data to be encrypted based on the character of the replacement index position in the base string.
[0039] According to a fourth aspect of this disclosure, a decryption device includes:
[0040] The first acquisition module is used to acquire the first index position of each character in the base string and the second index position in the data to be decrypted;
[0041] The second acquisition module is used to acquire the modulo operation result of the relevant function value of the second index bit and the length of the key string, and use it as the third index bit;
[0042] The third acquisition module is used to acquire the replacement index of decryption obfuscation for each character of the data to be decrypted based on the first index and the character in the key string corresponding to the third index.
[0043] The plaintext data generation module is used to generate plaintext data of the data to be decrypted based on the character of the replacement index position in the base string.
[0044] According to a fifth aspect of this disclosure, an electronic device includes:
[0045] Processor; and
[0046] Stored program memory,
[0047] The program includes instructions that, when executed by the processor, cause the processor to perform the method according to any one of the preceding descriptions.
[0048] According to a sixth aspect of this disclosure, a non-transitory computer-readable storage medium storing computer instructions for causing a computer to perform the method according to any one of the preceding statements.
[0049] According to a seventh aspect of this disclosure, a computer program product is characterized by comprising a computer program, wherein the computer program, when executed by a processor of a computer, is used to cause the computer to perform the method according to any one of the preceding claims.
[0050] One or more technical solutions provided in the embodiments of this application implement equal-length encryption based on replacing index bits, which reduces the computational complexity of equal-length encryption and improves encryption speed. Correspondingly, it can reduce decryption complexity and improve decryption speed.
[0051] In some technical solutions, different encryption and decryption modes are implemented based on the judgment result of whether the data to be encrypted or decrypted is digital data. This not only enables digital data to be encrypted into digital data, but also enables equal-length encryption of non-digital data, adapting to various special occasions and improving practicality. Attached Figure Description
[0052] The accompanying drawings illustrate exemplary embodiments of the present disclosure and, together with the description thereof, serve to explain the principles of the present disclosure. These drawings are included to provide a further understanding of the present disclosure and are incorporated in and constitute a part of this specification.
[0053] Figure 1 A flowchart of an encryption method according to an exemplary embodiment of the present disclosure is shown;
[0054] Figure 2 A sub-flowchart of an encryption method according to an exemplary embodiment of the present disclosure is shown;
[0055] Figure 3 A flowchart of a decryption method according to an exemplary embodiment of the present disclosure is shown;
[0056] Figure 4 A schematic block diagram of an encryption device according to an exemplary embodiment of the present disclosure is shown;
[0057] Figure 5 A schematic block diagram of a decryption apparatus according to an exemplary embodiment of the present disclosure is shown;
[0058] Figure 6 A structural block diagram of an exemplary electronic device that can be used to implement embodiments of the present disclosure is shown. Detailed Implementation
[0059] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0060] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.
[0061] The term "comprising" and its variations as used herein are open-ended, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the description below. It should be noted that the concepts of "first", "second", etc., used in this disclosure are only used to distinguish different devices, modules, or units, and are not intended to limit the order of functions performed by these devices, modules, or units or their interdependencies.
[0062] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".
[0063] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.
[0064] First, the definitions, variables, and calculations involved in the embodiments of this disclosure are explained as follows:
[0065] mBase: A basic mixed string composed of non-repeating characters such as numbers and English letters, which can be customized and extended.
[0066] mBaseNum: Basic numeric string, a string composed of non-repeating digits.
[0067] mKey: Key string. It can consist of data characters contained in mBase.
[0068] a%b: means taking the modulus of number a with respect to number b.
[0069] data.indexOf(c): Represents the index of the variable character c in the string data of data.
[0070] data.charAt(i): Represents the character at the corresponding index position of the index variable i (integer) in the data string.
[0071] The present disclosure is described below with reference to the accompanying drawings.
[0072] Example 1:
[0073] See Figure 1 One encryption method includes:
[0074] S101, obtain the first index of each character in the base string and the second index of each character in the data to be encrypted.
[0075] The base string in this embodiment is a string composed of non-repeating characters.
[0076] In some embodiments, before step S101, the data to be encrypted is obtained; it is determined whether the data to be encrypted is numeric data; if the data to be encrypted is numeric data, then a basic numeric string is used as the base string; otherwise, a basic mixed string is used as the base string. That is, in this embodiment, when obtaining the first index position mPos = f0(vc) of each character vc in the base string of the data to be encrypted, if the data to be encrypted is numeric data, then the base string is a basic numeric string, that is, the first index position of each character in the data to be encrypted is obtained in the basic numeric string mBaseNum; otherwise, the base string is a basic mixed string, that is, the first index position of each character in the data to be encrypted is obtained in the basic mixed string mBase. In this embodiment of the disclosure, the base string used is different when the data to be encrypted is numeric data (all characters in the data to be encrypted are numbers) and when it is non-numeric data. For ease of explanation and understanding, the encryption mode used when the data to be encrypted is numeric data is called MED encryption mode, and the encryption mode used when the data to be encrypted is non-numeric data is called fixed-length encryption mode. That is, in MED encryption mode, this step obtains the first index position f0(vc) = mBaseNum.indexOf(vc) of each character of the data to be encrypted in the base numeric string mBaseNum. In fixed-length encryption mode, this step obtains the first index position f0(vc) = mBase.indexOf(vc) of each character of the data to be encrypted in the base mixed string mBase.
[0077] For example, suppose the base numeric string is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] and the base mixed string is [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9].
[0078] Taking the data to be encrypted as "137" as an example, this data is numeric data. In this case, the MED encryption mode is used, and the base string is a basic numeric string. The first index position mPos of each character vc in the base string is denoted as mPos = f0(vc). The first index positions mPos are: f0(1) = 2, f0(3) = 4, f0(7) = 8. The second index positions vPos of each character vc in the data to be encrypted are: vPos(1) = 1, vPos(3) = 2, vPos(7) = 3. The characters in parentheses of vPos are for easy reading to indicate the second index position of the corresponding character. It should be understood that this example uses data to be encrypted without repeating characters for ease of understanding. However, in the real environment, the characters in the data to be encrypted may be repeated. It should be understood that the characters in parentheses of vPos refer to the character at the corresponding position, not all of the characters.
[0079] Taking the data to be encrypted as "paten" as an example, this data is non-numeric. Therefore, a fixed-length encryption mode is used, with a base string of mixed basic characters. The first index mPos of each character vc in the base string is denoted as mPos = f0(vc). The first index mPos are: f0(p) = 16, f0(a) = 1, f0(t) = 20, f0(e) = 5, f0(n) = 8. The second index vPos of each character vc in the data to be encrypted are: vPos(p) = 1, vPos(a) = 2, vPos(t) = 3, vPos(n) = 4.
[0080] It should be understood that the character order of the basic numeric string and the basic mixed string can be adjusted according to the actual request settings. The basic mixed string can be set according to actual needs, such as including uppercase and lowercase letters, special characters, etc.
[0081] S102: Obtain the modulo operation result of the relevant function value of the second index bit and the length of the key string, and use it as the third index bit.
[0082] In this step, the relevant function value for the second index bit can be any valid arithmetic function such as f1(vPos) = vPos, f1(vPos) = 2vPos + 1, etc. The key string can be a combination of characters from a basic mixed string.
[0083] In this step, the modulo operation between the relevant function value f1(vPos) of the second index vPos and the length of the key string mKey can be expressed as: keyPos = f1(vPos) % this.mKey.length(). Here, keyPos is the result of the length modulo operation, and f1(vPos) is the relevant function value of vPos, which can be any valid operation, such as f1(vPos) = vPos, f1(vPos) = vPos + 1, etc.
[0084] In one embodiment, the equivalent function value is used as the relevant function value for the second index bit, and the modulo operation result is obtained and used as the third index bit. Using the equivalent function value as the relevant function value for the second index bit simplifies the calculation steps and improves computational efficiency. However, using a non-equivalent function value as the relevant function value for the second index bit increases computational complexity but also increases the difficulty of decryption and improves security.
[0085] For example, suppose the base numeric string is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], the base mixed string is [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], and the key string is cba.
[0086] Taking the data to be encrypted as "137" and the related function for the second index as f1(vPos) = vPos as an example, the second index vPos of each character vc in the data to be encrypted are: vPos(1) = 1, vPos(3) = 2, vPos(7) = 3, this.mKey.length() = 3, and the modulo operation results keyPos of the related function value of the second index and the length of the key string are 1%3 = 1, 2%3 = 2, and 3%3 = 0 respectively.
[0087] Taking the data to be encrypted as "paten" and using the correlation function for the second index bit as f1(vPos) = vPos as an example, the second index bit vPos of each character vc in the data to be encrypted are: vPos(p) = 1, vPos(a) = 2, vPos(t) = 3, vPos(n) = 4, this.mKey.length() = 3. The modulo operation results keyPos of the correlation function value of the second index bit and the length of the key string are 1%3 = 1, 2%3 = 2, 3%3 = 0, and 4%3 = 1, respectively.
[0088] S103: Based on the first index position and the character corresponding to the third index position in the key string, obtain the replacement index position for encryption and obfuscation of each character in the data to be encrypted.
[0089] In this step, the replacement index for each character in the data to be encrypted is the replacement index of the corresponding first index. The first index is encrypted and obfuscated based on the third index, ensuring a relationship between the encrypted and obfuscated characters in the base string at the replacement index and the characters at the first index. The character in the key string corresponding to the third index corresponds to the second index. The corresponding character in the key string can be determined based on the second index position, allowing the first index to be encrypted and obfuscated based on that character. For example, the replacement index can be obtained by summing the index corresponding to the character and the first index. It should be understood that if this replacement index exceeds the total length of the base string, it can be modulo the total length of the base string. It should be understood that the corresponding calculation method is used during decryption to obtain the decrypted and obfuscated replacement index.
[0090] In one implementation, see Figure 2 Step S103 includes:
[0091] S201, based on the character corresponding to the third index position in the key string, obtain the fourth index position of the corresponding character in the basic mixed string.
[0092] S202, use the fourth index bit to encrypt and obfuscate the first index bit, so as to obtain the replacement index bit for encryption and obfuscation of each character of the data to be encrypted.
[0093] When using the fourth index bit to encrypt and obfuscate the first index bit, the replacement index bit for encryption and obfuscation is obtained by adding the first index bit and the fourth index bit. It should be understood that the result of the subtraction is used during decryption.
[0094] For example, based on the length modulo operation result keyPos (i.e., the third index bit) and the first index bit mPos, the character encryption replacement index bit resultPos corresponding to the data to be encrypted is obtained.
[0095] The calculation is as follows: If the DEM encryption mode is used, then resultPos and f2(keyPos) are defined as follows:
[0096] resultPos=(mPos+f2(keyPos))%mBaseNum.length();
[0097] f2(keyPos)=mBase.indexOf(mKey.charAt(keyPos))%mBaseNum.length();
[0098] Otherwise, it is defined as:
[0099] resultPos=(mPos+f2(keyPos))%mBase.length();
[0100] f2(keyPos)=mBase.indexOf(mKey.charAt(keyPos)).
[0101] For example, suppose the base numeric string is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], the base mixed string is [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], and the key string is cba.
[0102] Taking the data to be encrypted as "137" as an example, the correlation function value of the second index bit is f1(vPos) = vPos. The first index bit mPos of each character vc in the basic string is denoted as mPos = f0(vc), which are f0(1) = 2, f0(3) = 4, and f0(7) = 8, respectively. The modulo operation result keyPos of the correlation function value of the second index bit and the length of the key string are 1%3 = 1, 2%3 = 2, and 3%3 = 0, respectively. When keyPos is 0, mKey.charAt(keyPos) is generally the first character in mKey. In this embodiment, for ease of understanding and calculation, when keyPos is 0, mKey.charAt(keyPos) is the last character in mKey. Thus, when keyPos is 1, mKey.charAt(keyPos) is the first character in mKey, and so on. This part should be understood as being for the convenience of understanding and calculation, and should not be understood as a limitation of the technical solution disclosed herein.
[0103] The encryption replacement index for the character "1" is calculated as follows:
[0104] mKey.charAt(keyPos) = c;
[0105] mBase.indexOf(mKey.charAt(keyPos))=mBase.indexOf(c)=3;
[0106] mBaseNum.length() = 10;
[0107] f2(keyPos)=mBase.indexOf(mKey.charAt(keyPos))%mBaseNum.length()=3.
[0108] mPos=f0(1)=2;
[0109] resultPos=(mPos+f2(keyPos))%mBaseNum.length()=(2+3))%10=5.
[0110] The ciphertext character rc for the plaintext character "1" is the 5th character "4" in the underlying numeric string.
[0111] The encryption replacement index for the character "3" is calculated as follows:
[0112] mKey.charAt(keyPos) = b;
[0113] mBase.indexOf(mKey.charAt(keyPos))=mBase.indexOf(b)=2;
[0114] mBaseNum.length() = 10;
[0115] f2(keyPos)=mBase.indexOf(mKey.charAt(keyPos))%mBaseNum.length()=2.
[0116] mPos=f0(2)=4;
[0117] resultPos=(mPos+f2(keyPos))%mBaseNum.length()=(4+2))%10=6.
[0118] The ciphertext character rc of the plaintext character "3" is the 6th character "5" in the underlying numeric string.
[0119] The encryption replacement index for the character "7" is calculated as follows:
[0120] mKey.charAt(keyPos) = a;
[0121] mBase.indexOf(mKey.charAt(keyPos))=mBase.indexOf(b)=1;
[0122] mBaseNum.length() = 10;
[0123] f2(keyPos)=mBase.indexOf(mKey.charAt(keyPos))%mBaseNum.length()=1.
[0124] mPos=f0(3)=8;
[0125] resultPos=(mPos+f2(keyPos))%mBaseNum.length()=(8+1))%10=9.
[0126] The ciphertext character rc for the plaintext character "7" is the 9th character "8" in the underlying numeric string.
[0127] Taking the data to be encrypted as "paten" as an example, the first index position mPos of each character vc in the basic string is denoted as mPos = f0(vc), and the mPos are: f0(p) = 16, f0(a) = 1, f0(t) = 20, f0(e) = 5, f0(n) = 8. The second index position vPos of each character vc in the data to be encrypted are: vPos(p) = 1, vPos(a) = 2, vPos(t) = 3, vPos(n) = 4. The correlation function value of the second index position is f1(vPos) = vPos. The key string is cba. The modulo operation result keyPos of the correlation function value of the second index position and the length of the key string are 1%3 = 1, 2%3 = 2, 3%3 = 0, 4%3 = 1.
[0128] Based on the formula for calculating the encryption replacement index, let's take the calculation of the encryption replacement index for the character "p" as an example:
[0129] mKey.charAt(keyPos) = c;
[0130] mBase.indexOf(mKey.charAt(keyPos))=mBase.indexOf(c)=3;
[0131] f2(keyPos)=mBase.indexOf(mKey.charAt(keyPos))=3;
[0132] mPos = f0(p) = 16;
[0133] mBase.length() = 36;
[0134] resultPos=(mPos+f2(keyPos))%mBase.length()=(16+3)%36=19.
[0135] The ciphertext character rc of the plaintext character "p" is the 19th character S in the underlying mixed string.
[0136] S104: Generate ciphertext data of the data to be encrypted based on the character at the replacement index in the base string.
[0137] The encryption replacement index `resultPos` is obtained, corresponding to the character `rc` in the base string. These characters `rc` are then combined sequentially to generate the ciphertext data of the data to be encrypted. If the data to be encrypted is numeric, the DEM encryption mode is used, where the base string is a basic numeric string, and `rc = mBaseNum.charAt(resultPos)`. Otherwise, a fixed-length encryption mode is used, where the base string is a basic mixed string, and `rc = mBase.charAt(resultPos)`.
[0138] Example 2:
[0139] See Figure 3 One decryption method includes:
[0140] S301, obtain the first index of each character in the base string and the second index of each character in the data to be decrypted.
[0141] In some embodiments, when obtaining the first index position mPos = f0(vc) of each character vc in the ciphertext data in the base string, if the ciphertext data is numeric data, then the base string is a basic numeric string, that is, this step obtains the first index position of each character in the ciphertext data in the basic numeric string mBaseNum; otherwise, the base string is a basic mixed string, that is, this step obtains the first index position of each character in the ciphertext data in the basic mixed string mBase. In this embodiment of the disclosure, if the ciphertext data is numeric plaintext, then the DEM encryption mode is used; otherwise, the equal-length encryption mode is used. If the DEM encryption mode is used, then the first index position f0(vc) = mBaseNum.indexOf(vc) of each character in the ciphertext data in the base numeric string mBaseNum is obtained; if the equal-length encryption mode is used, then the first index position f0(vc) = mBase.indexOf(vc) of each character in the ciphertext data in the basic mixed string mBase is obtained.
[0142] S302: Obtain the modulo operation result of the relevant function value of the second index bit and the length of the key string, and use it as the third index bit.
[0143] S303: Based on the first index position and the character corresponding to the third index position in the key string, obtain the replacement index position for decryption obfuscation of each character in the data to be decrypted.
[0144] S304: Generate plaintext data of the data to be decrypted based on the character at the replacement index in the base string.
[0145] In one embodiment, before obtaining the first index position of each character in the base string and the second index position in the data to be decrypted, the method further includes: obtaining the data to be decrypted; determining whether the data to be decrypted is numeric data; if the data to be decrypted is numeric data, then using the base numeric string as the base string, otherwise using the base mixed string as the base string.
[0146] In one embodiment, obtaining the modulo operation result of the relevant function value of the second index bit and the length of the key string as the third index bit includes: using the equivalent function value as the relevant function value of the second index bit, obtaining the modulo operation result as the third index bit.
[0147] In one embodiment, obtaining the replacement index of the encryption and obfuscation of each character of the data to be decrypted based on the first index and the character corresponding to the third index in the key string includes: obtaining the fourth index of the corresponding character in the basic mixed string based on the character corresponding to the third index in the key string; and using the fourth index to encrypt and obfuscate the first index to obtain the replacement index of the encryption and obfuscation of each character of the data to be decrypted.
[0148] For example, suppose the basic numeric string is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], the basic mixed string is [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], the ciphertext data is 458 (the encrypted data of the previously mentioned data 137), the correlation function value of the second index is f1(vPos) = vPos, the key string is cba, and the first index mPos of each character of the ciphertext data in the basic string are f0(4) = 5, f0(5) = 6, f0(8) = 9, and the modulo operation result keyPos of the correlation function value of the second index and the length of the key string are 1%3 = 1, 2%3 = 2, 3%3 = 0.
[0149] According to the formula for calculating the decryption replacement index, the decryption replacement index for the character "4" is calculated as follows:
[0150] mKey.charAt(keyPos) = c;
[0151] mBase.indexOf(mKey.charAt(keyPos))=mBase.indexOf(c)=3;
[0152] mBaseNum.length() = 10;
[0153] f2(keyPos)=mBase.indexOf(mKey.charAt(keyPos))%mBaseNum.length()=3.
[0154] mPos=f0(4)=5;
[0155] resultPos=(mPos-f2(keyPos)+mBaseNum.length())%mBaseNum.length()=(5-3+10)%10=2;
[0156] The plaintext character rc of the ciphertext character "4" is the second character 1 in the underlying numeric string.
[0157] According to the formula for calculating the decryption replacement index, the encryption replacement index for the character "5" is calculated as follows:
[0158] mKey.charAt(keyPos) = b;
[0159] mBase.indexOf(mKey.charAt(keyPos))=mBase.indexOf(b)=2;
[0160] mBaseNum.length() = 10;
[0161] f2(keyPos)=mBase.indexOf(mKey.charAt(keyPos))%mBaseNum.length()=2.
[0162] mPos=f0(5)=6;
[0163] resultPos=(mPos-f2(keyPos)+mBaseNum.length())%mBaseNum.length()=(6-2+10)%10=4;
[0164] The ciphertext character rc for the plaintext character "5" is the fourth character 3 in the underlying numeric string.
[0165] According to the formula for calculating the decryption replacement index, the encryption replacement index for the character "9" is calculated as follows:
[0166] mKey.charAt(keyPos) = a;
[0167] mBase.indexOf(mKey.charAt(keyPos))=mBase.indexOf(b)=1;
[0168] mBaseNum.length() = 10;
[0169] f2(keyPos)=mBase.indexOf(mKey.charAt(keyPos))%mBaseNum.length()=1.
[0170] mPos=f0(8)=9;
[0171] resultPos=(mPos-f2(keyPos)+mBaseNum.length())%mBaseNum.length()=(9-1+10)%10=8.
[0172] The ciphertext character rc for the plaintext character "9" is the 8th character "7" in the underlying numeric string.
[0173] As can be seen, the data after decryption of ciphertext data 458 is 137.
[0174] Similarly, for example, suppose the basic numeric string is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], the basic mixed string is [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], the ciphertext data is st, and the key string is cba.
[0175] Based on the formula for calculating the encryption replacement index, let's take the calculation of the decryption replacement index for the character "s" as an example:
[0176] mKey.charAt(keyPos) = c;
[0177] mBase.indexOf(mKey.charAt(keyPos))=mBase.indexOf(c)=3;
[0178] f2(keyPos)=mBase.indexOf(mKey.charAt(keyPos))=3;
[0179] mPos=f0(s=19;
[0180] mBase.length() = 36;
[0181] resultPos=(mPos-f2(keyPos))%mBase.length()=(19-3)%36=16.
[0182] The ciphertext character rc of the plaintext character "s" is the 16th character p in the underlying mixed string.
[0183] Example 3:
[0184] See Figure 4 An encryption device, comprising:
[0185] The first acquisition module 401 is used to acquire the first index position of each character in the base string and the second index position in the data to be encrypted.
[0186] The second acquisition module 402 is used to acquire the modulo operation result of the relevant function value of the second index bit and the length of the key string, and use it as the third index bit.
[0187] The third acquisition module 403 is used to obtain the replacement index of encryption and obfuscation for each character of the data to be encrypted based on the first index and the character corresponding to the third index in the key string.
[0188] The ciphertext data generation module 404 is used to generate ciphertext data of the data to be encrypted based on the characters at the replacement index positions in the base string.
[0189] In some embodiments, the apparatus further includes a determination module, configured to acquire the data to be encrypted; determine whether the data to be encrypted is numeric data; if the data to be encrypted is numeric data, then use a basic numeric string as the base string, otherwise use a basic mixed string as the base string.
[0190] In some embodiments, when the second acquisition module 402 is used to acquire the modulo operation result of the relevant function value of the second index bit and the key string length as the third index bit, it is specifically used to: use the equivalent function value as the relevant function value of the second index bit, acquire the modulo operation result, and use it as the third index bit.
[0191] In some embodiments, the third acquisition module 403 is used to obtain the replacement index of the encryption and obfuscation of each character of the data to be encrypted based on the first index and the character corresponding to the third index in the key string. Specifically, it is used to: obtain the fourth index of the corresponding character in the basic mixing string based on the character corresponding to the third index in the key string; and use the fourth index to encrypt and obfuscate the first index to obtain the replacement index of the encryption and obfuscation of each character of the data to be encrypted.
[0192] Example 4:
[0193] See Figure 5 A decryption device, comprising:
[0194] The first acquisition module 501 is used to acquire the first index position of each character in the base string and the second index position in the data to be decrypted;
[0195] The second acquisition module 502 is used to acquire the modulo operation result of the relevant function value of the second index bit and the length of the key string, and use it as the third index bit;
[0196] The third acquisition module 503 is used to acquire the replacement index of decryption obfuscation for each character of the data to be decrypted based on the first index and the character corresponding to the third index in the key string;
[0197] The plaintext data generation module 504 is used to generate plaintext data of the data to be decrypted based on the characters at the replacement index positions in the base string.
[0198] In some embodiments, the decryption module further includes a judgment module, configured to: obtain the data to be decrypted; determine whether the data to be decrypted is numeric data; if the data to be decrypted is numeric data, use a basic numeric string as the base string, otherwise use a basic mixed string as the base string.
[0199] In some embodiments, when the second acquisition module 502 is used to acquire the modulo operation result of the relevant function value of the second index bit and the key string length as the third index bit, it is specifically used to: use the equivalent function value as the relevant function value of the second index bit, acquire the modulo operation result, and use it as the third index bit.
[0200] In some embodiments, when the third acquisition module 503 is used to acquire the replacement index of the encryption and obfuscation of each character of the data to be decrypted based on the first index and the character corresponding to the third index in the key string, it is specifically used to: acquire the fourth index of the corresponding character in the basic mixed string based on the character corresponding to the third index in the key string; and use the fourth index to encrypt and obfuscate the first index to obtain the replacement index of the encryption and obfuscation of each character of the data to be decrypted.
[0201] Exemplary embodiments of this disclosure also provide an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores a computer program executable by the at least one processor, which, when executed by the at least one processor, causes the electronic device to perform a method according to an embodiment of this disclosure.
[0202] Exemplary embodiments of this disclosure also provide a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a computer's processor, is used to cause the computer to perform a method according to embodiments of this disclosure.
[0203] Exemplary embodiments of this disclosure also provide a computer program product, including a computer program, wherein the computer program, when executed by a computer's processor, is used to cause the computer to perform a method according to an embodiment of this disclosure.
[0204] refer to Figure 6 The present invention describes a structural block diagram of an electronic device 600 that can serve as a server or client of the present disclosure, which is an example of a hardware device that can be applied to various aspects of the present disclosure. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0205] Electronic device 600 includes a computing unit 601, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 602 or a computer program loaded into random access memory (RAM) 603 from storage unit 608. The RAM 603 may also store various programs and data required for device operation. The computing unit 601, ROM 602, and RAM 603 are interconnected via bus 604. An input / output (I / O) interface 605 is also connected to bus 604.
[0206] Multiple components in electronic device 600 are connected to I / O interface 605, including: input unit 606, output unit 607, storage unit 608, and communication unit 609. Input unit 606 can be any type of device capable of inputting information to electronic device 600. Input unit 606 can receive input digital or character information and generate key signal inputs related to user settings and / or function control of electronic device. Output unit 607 can be any type of device capable of presenting information and may include, but is not limited to, a display, speaker, video / audio output terminal, vibrator, and / or printer. Storage unit 608 may include, but is not limited to, disks and optical discs. Communication unit 609 allows electronic device 600 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks, and may include, but is not limited to, modems, network cards, infrared communication devices, wireless communication transceivers, and / or chipsets, such as Bluetooth™ devices, WiFi devices, WiMax devices, cellular communication devices, and / or the like.
[0207] The computing unit 601 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 601 performs the various methods and processes described above. For example, in some embodiments, the methods of the embodiments of this disclosure can be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 608. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 600 via ROM 602 and / or communication unit 609. In some embodiments, the computing unit 601 can be configured to perform the methods of the embodiments of this disclosure by any other suitable means (e.g., by means of firmware).
[0208] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0209] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0210] As used in this disclosure, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or apparatus (e.g., disk, optical disk, memory, programmable logic device) for providing machine instructions and / or data to a programmable processor, including machine-readable media that receive machine instructions as machine-readable signals. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0211] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0212] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with embodiments of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.
[0213] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other.
Claims
1. An encryption method, characterized in that, include: Obtain the first index of each character in the base string and the second index in the data to be encrypted; Obtain the modulo operation result of the relevant function value of the second index bit and the length of the key string, and use it as the third index bit; Based on the first index position and the character in the key string corresponding to the third index position, obtain the replacement index position for encryption and obfuscation of each character of the data to be encrypted; The ciphertext data of the data to be encrypted is generated based on the character at the replacement index position in the base string.
2. The method according to claim 1, characterized in that, Before obtaining the first index of each character in the base string and the second index in the data to be encrypted, the method further includes: Obtain the data to be encrypted; Determine whether the data to be encrypted is digital data; If the data to be encrypted is numeric data, then a basic numeric string is used as the base string; otherwise, a basic mixed string is used as the base string.
3. The method according to claim 1, characterized in that, The step of obtaining the modulo operation result of the relevant function value of the second index bit and the key string length, and using it as the third index bit, includes: The modulo operation result is obtained by using the equivalent function value as the relevant function value of the second index bit, and then used as the third index bit.
4. The method according to claim 1, characterized in that, The step of obtaining the replacement index for encryption and obfuscation of each character in the data to be encrypted based on the first index bit and the character in the key string corresponding to the third index bit includes: Based on the character corresponding to the third index position in the key string, obtain the fourth index position of the corresponding character in the basic mixed string; The first index bit is encrypted and obfuscated using the fourth index bit to obtain the replacement index bit for the encryption and obfuscation of each character of the data to be encrypted.
5. A decryption method, characterized in that, include: Obtain the first index of each character in the base string and the second index in the data to be decrypted; Obtain the modulo operation result of the relevant function value of the second index bit and the length of the key string, and use it as the third index bit; Based on the first index position and the character in the key string corresponding to the third index position, obtain the replacement index position for decryption obfuscation of each character in the data to be decrypted; The plaintext data of the data to be decrypted is generated based on the character at the replacement index in the base string.
6. The method according to claim 5, characterized in that, Before obtaining the first index of each character in the base string and the second index of the data to be decrypted, the method further includes: Obtain the data to be decrypted; Determine whether the data to be decrypted is digital data; If the data to be decrypted is numeric data, then a basic numeric string is used as the base string; otherwise, a basic mixed string is used as the base string. or, The step of obtaining the modulo operation result of the relevant function value of the second index bit and the key string length, and using it as the third index bit, includes: Using the equivalent function value as the relevant function value of the second index bit, the result of the modulo operation is obtained and used as the third index bit; or, The step of obtaining the replacement index for encryption and obfuscation of each character in the data to be decrypted based on the first index bit and the character in the key string corresponding to the third index bit includes: Based on the character corresponding to the third index position in the key string, obtain the fourth index position of the corresponding character in the basic mixed string; The first index bit is encrypted and obfuscated using the fourth index bit to obtain the replacement index bit for the encryption and obfuscation of each character of the data to be decrypted.
7. An encryption device, characterized in that, include: The first acquisition module is used to acquire the first index position of each character in the base string and the second index position in the data to be encrypted; The second acquisition module is used to acquire the modulo operation result of the relevant function value of the second index bit and the length of the key string, and use it as the third index bit; The third acquisition module is used to acquire the replacement index of encryption and obfuscation for each character of the data to be encrypted based on the first index and the character in the key string corresponding to the third index. The ciphertext data generation module is used to generate ciphertext data of the data to be encrypted based on the character of the replacement index position in the base string.
8. A decryption device, characterized in that, include: The first acquisition module is used to acquire the first index position of each character in the base string and the second index position in the data to be decrypted; The second acquisition module is used to acquire the modulo operation result of the relevant function value of the second index bit and the length of the key string, and use it as the third index bit; The third acquisition module is used to acquire the replacement index of decryption obfuscation for each character of the data to be decrypted based on the first index and the character in the key string corresponding to the third index. The plaintext data generation module is used to generate plaintext data of the data to be decrypted based on the character of the replacement index position in the base string.
9. An electronic device, characterized in that, include: processor; as well as Stored program memory, The program includes instructions that, when executed by the processor, cause the processor to perform the method according to any one of claims 1-6.
10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-6.
11. A computer program product, characterized in that, Includes a computer program, wherein the computer program, when executed by a computer's processor, is used to cause the computer to perform the method according to any one of claims 1-6.
Citation Information
Patent Citations
Encryption method and?device
CN103825723A
Data security processing method and apparatus
CN106059762A