A Primality Testing Method, System, Device and Medium in Ciphertext State
By combining all-homomorphic encryption technology and pre-stored prime number list, a prime quality testing method in ciphertext state is designed, which solves the problems of high computing complexity and memory consumption in the existing technology, and realizes efficient prime quality testing and data privacy protection, which is suitable for cloud computing and other scenarios.
Patent Information
- Application Number
- CN202510251808.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-05
- Publication Date
- 2025-05-27
- Estimated Expiration
- 2045-03-05
AI Technical Summary
It is difficult for the prior art to achieve efficient primary testing in a fully homomorphic encryption environment, especially in the ciphertext state. Traditional methods have problems with high computing complexity and memory consumption, and cannot be directly applied to scenarios such as cloud computing that require high data confidentiality.
By combining all-homomorphic encryption technology and pre-stored prime number list, a primeness test method in the ciphertext state is designed. The symbol function shsign(x) is used to judge the numerical size, and dynamically adjust the values of encrypted ciphertexts a and b, calculate their maximum common factors, and realize efficient primeness test.
This method significantly reduces computational complexity and memory consumption, improves the efficiency and accuracy of the algorithm, is suitable for large-scale data processing, and provides a high level of data privacy protection in cloud computing environments.
Smart Images

Figure CN119814312B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data privacy protection, and more particularly to a method, system, device and medium for prime testing in ciphertext state. Background Art
[0002] In the field of data privacy protection, especially in the application of fully homomorphic encryption (FHE), how to process encrypted information without decrypting the data has become a key research direction. With the development of the Internet, mobile Internet and Internet of Things, the amount of data has increased explosively, and the security and privacy of data have become the focus of people's attention.
[0003] Fully homomorphic encryption allows performing computational operations directly on encrypted data without exposing the original data content, providing a revolutionary solution to the problem of data privacy. However, in practical applications, especially when complex operations such as prime testing are required, traditional methods often fail to meet the requirements.
[0004] The existing prime testing methods mainly include the direct method and the screening method, but these methods all have significant defects. The direct method determines whether a number is prime by checking whether it can be divided evenly by all numbers less than it. This method not only involves division operations that are difficult to implement in a homomorphic encryption environment, but also has a high time complexity and is extremely inefficient for large-scale data sets or large numerical values. On the other hand, although the screening method can effectively find all prime numbers within a certain range, its memory consumption is huge and the time complexity is high. Especially when dealing with the prime judgment of a single large number, the efficiency is low and it is not suitable for application scenarios in the context of fully homomorphic encryption.
[0005] Furthermore, it cannot be directly applied to prime testing in ciphertext state. Due to the special nature of fully homomorphic encryption, traditional mathematical operations such as division and boolean array operations are difficult to effectively implement, resulting in the existing prime testing methods being unable to provide efficient computational performance while ensuring data privacy. In addition, traditional methods lack the ability to directly perform operations on ciphertext data, restricting their application in scenarios such as cloud computing that require high data confidentiality.
[0006] Therefore, how to design a prime testing method in ciphertext state that can overcome the problems of high computational complexity and memory consumption existing in the prior art while ensuring data privacy, and at the same time support directly performing necessary mathematical operations on encrypted data is an urgent problem to be solved by those skilled in the art. Summary of the Invention
[0007] In view of this, the present invention provides a method for prime number testing in ciphertext state, which can utilize the advantages of fully homomorphic encryption technology to achieve fast prime number testing of encrypted data without exposing the plaintext data, so as to meet the growing needs of data security and privacy protection, and at the same time improve the efficiency and flexibility of data processing.
[0008] To achieve the above object, the present invention adopts the following technical solutions:
[0009] In a first aspect, the present invention provides a method for prime number testing in ciphertext state, including the following steps:
[0010] S1. Determine an array a[max] as a prime number list based on the prime number testing range, and write a sign function shsign(x) in combination with a fully homomorphic encryption library;
[0011] S2. Traverse the prime number list, use the difference n - a[i] between the number n to be tested and each prime number a[i] in the prime number list as a parameter to call the shsign function, store the result shsign(n - a[i]) in the array b[i], and accumulate and sum the array b[i] to obtain the result k;
[0012] S3. Calculate the difference between the encrypted ciphertext a of the number n to be tested and the encrypted ciphertext b of any element in the prime number list, and call the shsign function to obtain the ciphertext value c;
[0013] S4. Dynamically assign values to the encrypted ciphertext a and the encrypted ciphertext b using the ciphertext value c, and calculate the greatest common divisor of the encrypted ciphertext a and the encrypted ciphertext b;
[0014] S5. Repeat the steps S3 - S4 until all elements in the prime number list are traversed to obtain max greatest common divisors;
[0015] S6. Accumulate and sum the max greatest common divisors to obtain the result t, and call the shsign function to obtain the result j;
[0016] S7. Add k and j, and complete the prime number testing in ciphertext state based on the addition result.
[0017] Further, in the S1, determining an array a[max] as a prime number list based on the prime number testing range includes:
[0018] If the prime number testing range is 2 m , then all prime numbers less than or equal to are stored in the array a[max] as the prime number list; where max represents the number of stored prime numbers.
[0019] Further, in S1, the sign function shsign(x) is used to determine whether the plaintext value of the ciphertext x is equal to 0 and output the corresponding ciphertext result, including: if the plaintext value of the ciphertext x is equal to 0, output the ciphertext of 1; otherwise, output the ciphertext of 0.
[0020] Further, in S4, the encrypted ciphertext a and the encrypted ciphertext b are dynamically assigned values using the ciphertext value c, including:
[0021] Assign (1 - c) * a + c * b to a to ensure that the ciphertext a is the larger value;
[0022] Assign c * a + (1 - c) * b to b to ensure that the ciphertext b is the smaller value.
[0023] Further, in S4, calculating the greatest common divisor of the encrypted ciphertext a and the encrypted ciphertext b includes:
[0024] S41. Store b * 2 in the array d[i] i , which is used to accelerate the iterative calculation of the greatest common divisor;
[0025] S42. Use the array c[i] to mark whether a - d[i] is non - negative, and use the array s[i]=c[i + 1]-c[i] to mark whether d[i] is the largest binary coefficient less than a;
[0026] S43. Accumulate and sum through the array t[i]=s[i]*d[i] to obtain the largest binary coefficient, and iteratively calculate the greatest common divisor of a - b * 2 i and b until the maximum number of iterations is reached, and output the greatest common divisor of a and b.
[0027] Further, in S43, the maximum number of iterations is:
[0028]
[0029] where represents the ceiling function, represents taking the larger value of a and b.
[0030] Further, in S7, based on the addition result, perform a primality test in the encrypted ciphertext state, including: if the addition result is 1, then n is a prime number; if the addition result is 0, then n is a composite number.
[0031] In a second aspect, the present invention provides a primality test system in the encrypted ciphertext state, including:
[0032] Initialization module: used to determine the array a[max] as a prime number list based on the prime test range, and write the symbolic function shsign(x) in combination with the fully homomorphic encryption library;
[0033] Difference symbol calculation and accumulation module: used to traverse the prime number list, take the difference n - a[i] between the number to be tested n and each prime number a[i] in the prime number list as a parameter to call the shsign function, store the result shsign(n - a[i]) in the array b[i], and accumulate and sum the array b[i] to obtain the result k;
[0034] Ciphertext difference symbol calculation module: used to perform difference calculation on the encrypted ciphertext a of the number to be tested n and the encrypted ciphertext b of any element in the prime number list, and call the shsign function to obtain the ciphertext value c;
[0035] Greatest common divisor calculation module: used to dynamically assign values to the encrypted ciphertext a and the encrypted ciphertext b using the ciphertext value c, and calculate the greatest common divisor of the encrypted ciphertext a and the encrypted ciphertext b;
[0036] Greatest common divisor collection module: used to traverse all elements in the prime number list to obtain max greatest common divisors;
[0037] Greatest common divisor accumulation module: used to accumulate and sum the max greatest common divisors to obtain the result t, and call the shsign function to obtain the result j;
[0038] Primality judgment module: used to add k and j, and complete the primality test in the ciphertext state based on the addition result.
[0039] In a third aspect, the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the above-mentioned primality test method in the ciphertext state is implemented.
[0040] In a fourth aspect, the present invention provides a computer-readable storage medium. The storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned primality test method in the ciphertext state is implemented.
[0041] For the descriptions of the second to fourth aspects of the present invention, reference can be made to the detailed description of the first aspect; and for the beneficial effects of the descriptions of the second to fourth aspects, reference can be made to the analysis of the beneficial effects of the first aspect, which will not be elaborated here.
[0042] Through the above technical solutions, compared with the prior art, the present invention has the following beneficial effects:
[0043] 1. This method realizes efficient primality testing of large numbers in ciphertext state through fully homomorphic encryption and a pre-stored prime number list. Compared with traditional direct methods and screening methods, it avoids the need for direct division operations, greatly reduces the computational complexity, and decreases the memory consumption. By using the sign function shsign(x) to judge the numerical size, the efficiency and accuracy of the algorithm are further improved, making it more feasible when dealing with large-scale data.
[0044] 2. It also combines a dynamic adjustment mechanism that can automatically adjust the values of encrypted ciphertexts a and b according to different numbers n to be tested, ensuring the accuracy and efficiency of the greatest common divisor calculation. In addition, through iterative calculation and gradually narrowing the range until the greatest common divisor of two numbers is found, it is not only applicable to numbers of a specific size but can also be extended to a larger range of primality testing. It can maintain good performance for both small-scale and large-scale data sets.
[0045] 3. This method is particularly suitable for data privacy protection in cloud computing environments, allowing complex mathematical operations to be performed without exposing the original data. Using fully homomorphic encryption, users can securely send encrypted data to the cloud for processing without worrying about the risk of data leakage. This feature is particularly important for application scenarios that require high data confidentiality (such as finance, healthcare, etc.), effectively preventing sensitive information from being obtained by unauthorized third parties. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained according to the provided drawings.
[0047] Figure 1 It is a flowchart of a primality testing method in ciphertext state provided by an embodiment of the present invention;
[0048] Figure 2 It is a schematic diagram of the process of calculating the greatest common divisor of encrypted ciphertext a and encrypted ciphertext b provided by an embodiment of the present invention;
[0049] Figure 3 It is a schematic diagram of the implementation process of primality testing provided by an embodiment of the present invention;
[0050] Figure 4 It is a framework diagram of a primality testing system in ciphertext state provided by an embodiment of the present invention;
[0051] Figure 5 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Specific Embodiments
[0052] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0053] The prime number testing method provided by the embodiments of the present application can be applied to a prime number testing server, which can be hardware or software. When the prime number testing server is hardware, it can be implemented as a distributed server cluster providing prime number testing services or as a single server. When the prime number testing server is software, it can be installed in the servers listed above. It can be implemented as multiple software or software modules, or as a single software or software module, and no specific limitation is made here.
[0054] Embodiment 1
[0055] As Figure 1 shown, this embodiment provides a prime number testing method in the ciphertext state, including the following steps:
[0056] S1. Determine the array a[max] as the prime number list based on the prime number testing range, and write the symbol function shsign(x) in combination with the fully homomorphic encryption library;
[0057] S2. Traverse the prime number list, use the difference n - a[i] between the number to be tested n and each prime number a[i] in the prime number list as a parameter to call the shsign function, store the result shsign(n - a[i]) in the array b[i], and accumulate and sum the array b[i] to obtain the result k;
[0058] S3. Perform a difference calculation on the encrypted ciphertext a of the number to be tested n and the encrypted ciphertext b of any element in the prime number list, and call the shsign function to obtain the ciphertext value c;
[0059] S4. Dynamically assign values to the encrypted ciphertext a and the encrypted ciphertext b using the ciphertext value c, and calculate the greatest common divisor of the encrypted ciphertext a and the encrypted ciphertext b;
[0060] S5. Repeat the steps S3 - S4 until all elements in the prime number list are traversed to obtain max greatest common divisors;
[0061] S6. Accumulate and sum the max greatest common divisors to obtain the result t, and call the shsign function to obtain the result j;
[0062] S7. Add k and j, and perform a primality test in the ciphertext state based on the addition result.
[0063] By combining fully homomorphic encryption and primality test algorithms, this method realizes efficient prime number judgment in the ciphertext state, avoiding the problems of division operations and high memory consumption in traditional methods. Its core advantage lies in significantly improving the computational efficiency by pre-storing a prime number list and optimizing the calculation of the greatest common divisor, while ensuring data privacy, and is applicable to scenarios such as cloud computing that require data security protection.
[0064] The following further elaborates on each step in the above method:
[0065] In this embodiment S1, based on the primality test range, determine the array a[max] as the prime number list, and write the sign function shsign(x) in combination with the fully homomorphic encryption library;
[0066] Among them, determining the array a[max] as the prime number list based on the primality test range includes: If the primality test range is 2 m , then store all prime numbers less than or equal to in the array a[max] as the prime number list; where max represents the number of stored prime numbers.
[0067] According to the trial division method, it can be determined whether n is a prime number by traversing to the square root of n, which can be proved by contradiction: Assume that it is still impossible to determine whether n is a prime number after traversing to the square root of n, then there exist natural numbers a and b such that n = a * b, and at the same time, one of a and b is greater than the square root of n. If one of a and b is greater than the square root of n and the other is less than the square root of n, then the smaller number will be traversed before traversing to the square root of n, which contradicts the assumption; if both a and b are greater than the square root of n, then a * b > n, which also contradicts the assumption. Therefore, the proof holds.
[0068] Here, taking the determination of whether the data n within 2 14 is a prime number as an example, the determination of the prime number list is further elaborated. Since a prime number can be determined by judging whether the square root of n is a prime number, when performing prime number determination, only prime numbers less than 2 7 (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127) need to be stored in the prime number list. There are 31 prime numbers in total, that is, the number of stored prime numbers max is 31.
[0069] The above sign function shsign(x) is used to determine whether the plaintext value of the ciphertext x is equal to 0 and output the corresponding ciphertext result, including: if the plaintext value of the ciphertext x is equal to 0, output the ciphertext of 1; otherwise, output the ciphertext of 0.
[0070] Further, traverse the prime number list, use the difference n - a[i] between the number n to be tested and each prime number a[i] in the prime number list as a parameter to call the shsign function, store the result shsign(n - a[i]) in the array b[i], and accumulate and sum the array b[i] to obtain the result k.
[0071] Further, calculate the difference between the encrypted ciphertext a of the number n to be tested and the encrypted ciphertext b of any element in the prime number list, and call the shsign function to obtain the ciphertext value c.
[0072] Further, use the ciphertext value c to dynamically assign values to the encrypted ciphertext a and the encrypted ciphertext b, and calculate the greatest common divisor of the encrypted ciphertext a and the encrypted ciphertext b. Among them, using the ciphertext value c to dynamically assign values to the encrypted ciphertext a and the encrypted ciphertext b includes:
[0073] Assign (1 - c) * a + c * b to a to ensure that the ciphertext a is the larger value; assign c * a + (1 - c) * b to b to ensure that the ciphertext b is the smaller value.
[0074] Here, the ciphertext value c is used to dynamically assign values to the encrypted ciphertext a and b, ensuring that a is always the larger value and b is the smaller value in each iteration. Specifically, assign (1 - c)*a + c*b to a, and c*a + (1 - c)*b to b, and use the value of c (the ciphertext form of 0 or 1) to control the size relationship between a and b. This dynamic assignment mechanism ensures that during the calculation of the greatest common divisor, the values of a and b can gradually converge, thus efficiently completing the GCD calculation in the ciphertext state while avoiding the risk of plaintext exposure.
[0075] Further, as Figure 2 shown, calculating the greatest common divisor of the encrypted ciphertext a and the encrypted ciphertext b includes:
[0076] S41. Store b * 2 in the array d[i] i for accelerating the iterative calculation of the greatest common divisor;
[0077] S42. Use the array c[i] to mark whether a - d[i] is non - negative, and use the array s[i] = c[i + 1] - c[i] to mark whether d[i] is the largest binary coefficient less than a.
[0078] S43. The maximum binary coefficient is obtained by cumulative summation of t[i] = s[i] * d[i], and a - b * 2 is iteratively calculated i the greatest common divisor of a and b until the maximum number of iterations is reached, and the greatest common divisor of a and b is output.
[0079] The following further explains each array at this point in combination with the value of i. For the array d[i], in order to ensure that the array d[i] contains enough elements to cover the possible iteration range, the value of i needs to be set starting from 0 until the maximum value max. Therefore, the loop condition is set to i = 0; i ≤ max; i++; in this way, the d array will contain max + 1 elements; since the array d[i] has max + 1 elements, after performing the shsign operation on each d[i], the array c[i] will have max + 1 corresponding results.
[0080] In practical applications, in order to ensure that the largest b * 2 just less than a can be correctly calculated i , the last element in the array c[i] needs to be ignored and not directly used in the calculation of the greatest common divisor for the last element (corresponding to i = max). Therefore, when calculating s[i] and t[i], the loop condition is set to i = 0; i ≤ max - 1; i++; both s[i] and t[i] will contain max elements.
[0081] Furthermore, through the following implementation process, the calculation of the greatest common divisor of a and b by iterative operation is further explained:
[0082] The input parameters include: a = 1023, b = 1, max_size = 20 representing the maximum index of the array, and max = 10 representing the maximum index value actually used in this implementation process. The array definition and initialization include: d[i] is initialized as an array from 1 to 1024, c[i] is initialized as an array from 0 to 1, s[i] is initialized as an array from 0 to 1, and t[i] is initialized as an array from 0 to 512.
[0083] The iterative process continuously reduces the value of a and maintains b as 1 until a is reduced to less than or equal to 0. The specific iteration is as follows:
[0084] In the first iteration, with the initial values a = 1023 and b = 1, the largest non - zero element in t[i] is found to be 512, and a is updated to a = a - 512 = 511.
[0085] In the second iteration, with the updated values a = 511 and b = 1, the largest non - zero element in t[i] is found to be 256, and a is updated to a = a - 256 = 255.
[0086] For subsequent iterations, continue to repeat the above process and gradually decrease the value of a: for the third iteration, a = 255 - 128 = 127; for the fourth iteration, a = 127 - 64 = 63; for the fifth iteration, a = 63 - 32 = 31; for the sixth iteration, a = 31 - 16 = 15; for the seventh iteration, a = 15 - 8 = 7; for the eighth iteration, a = 7 - 4 = 3; for the ninth iteration, a = 3 - 2 = 1; for the tenth iteration, a = 1 - 1 = 0; finally, the output is a = 1, at this time a is equal to b, and the algorithm ends.
[0087] By constructing arrays d[i], c[i], s[i] and t[i], and using these arrays for iterative operations, gradually reduce the gap between a and b, and finally find the greatest common divisor of a and b.
[0088] Furthermore, the maximum number of iterations is:
[0089]
[0090] where represents the ceiling function, represents the larger value of a and b.
[0091] Here, a further explanation of the setting of the maximum number of iterations is given. In the first iteration, there are two possible cases:
[0092] Case 1: a > a / 2 > b; this means that the value of a is much larger than b, and the value of a is at least twice that of b; in this case, the ranges of a and b will be significantly reduced because the value of a is reduced by at least more than half of the original.
[0093] Case 2: a > b > a / 2; this means that the value of a is larger than b, but the value of b is still greater than a / 2; in this case, the ranges of a and b are not reduced significantly because b is still close to a / 2. However, since the ciphertext value c is used to dynamically assign values to the encrypted ciphertext a and the encrypted ciphertext b during each iteration, ensuring that a > b, then there must be a / 2 > b / 2, so there must be a > b > a / 2 > b / 2 at this time. Therefore, after the second iteration, it is certain to ensure that it is reduced by more than half of the original.
[0094] In summary, since the range is reduced by at least half after each iteration, the maximum number of iterations set here can ensure that the calculation is completed within a finite number of iterations; in this way, the algorithm can efficiently calculate the greatest common divisor under ciphertext, and then realize the judgment of prime numbers.
[0095] Furthermore, repeat the above steps until all elements in the prime number list are traversed to obtain max greatest common divisors;
[0096] Further, sum up the max greatest common divisors to obtain the result t, and call the shsign function to obtain the result j;
[0097] Add k and j, and complete the primality test in the ciphertext state based on the addition result. Specifically: if the addition result is 1, then n is a prime number; if the addition result is 0, then n is a composite number.
[0098] The following is a further detailed description of k and j based on different cases of n:
[0099] If n is a prime number within the range of the prime number list: k = 1 (because n is in the prime number list), j = 0 (because n is not within the range greater than the prime number list), j + k = 1, and it is determined that n is a prime number. If n is a composite number within the range of the prime number list: k = 0 (because n is not in the prime number list), j = 0 (because n is a composite number and the greatest common divisor with some numbers in the prime number list is not 1), j + k = 0, and it is determined that n is a composite number. If n is a prime number greater than the range of the prime number list: k = 0 (because n is not in the prime number list), j = 1 (because n is a prime number and the greatest common divisor with each number in the prime number list is 1), j + k = 1, and it is determined that n is a prime number. If n is a composite number greater than the range of the prime number list: k = 0 (because n is not in the prime number list), j = 0 (because n is a composite number and the greatest common divisor with some numbers in the prime number list is not 1), j + k = 0, and it is determined that n is a composite number.
[0100] The four cases of n and the output results are shown in the following table:
[0101] Case of n The first result k The second result j k + j Prime numbers less than the prime number list 1 0 1 Composite numbers less than the prime number list 0 0 0 Prime numbers greater than the prime number list 0 1 1 Composite numbers greater than the prime number list 0 0 0
[0102] Therefore, based on the result of j + k, it can be determined whether n is a prime number: if j + k = 1, then n is a prime number; if j + k = 0, then n is a composite number.
[0103] This embodiment outlines an innovative primality test method in the ciphertext state. By predefining a prime number list, combining the sign function in the fully homomorphic encryption technology, and dynamically calculating the greatest common divisor, it realizes the efficient determination of whether the number to be tested is a prime number without decrypting the data, effectively protects data privacy, and significantly improves the calculation efficiency. It can be widely applied to scenarios with high requirements for data privacy.
[0104] Embodiment 2;
[0105] In a cloud computing environment, users often need to process large-scale data sets. However, due to privacy protection requirements, they do not want to directly expose the original data. For example, when optimizing the parameters of an encryption algorithm, it is very valuable to understand the distribution of prime numbers in the data set. This embodiment shows how to use the prime number testing method in the above ciphertext state to help users count the distribution of prime numbers in the encrypted data set without revealing the data content.
[0106] Specifically, a user has a data set containing 10,000 integers and hopes to count the number of prime numbers in it through a cloud service to optimize the parameters of their encryption algorithm. To protect data privacy, the user first encrypts the data set using fully homomorphic encryption technology to generate a set of encrypted data {Enc(x1), Enc(x2), ..., Enc(x10000)}. Then, these encrypted data are uploaded to the cloud platform, and the cloud service is used to perform prime number testing in the ciphertext state.
[0107] As Figure 3 shown, the specific implementation process of prime number testing includes:
[0108] 1) Initialization phase: Based on the prime number testing range provided by the user, determine a pre-stored prime number list a[max]. Assuming m = 214, all prime numbers less than or equal to need to be stored as the prime number list. At the same time, write a sign function shsign(x) in combination with the fully homomorphic encryption library for subsequent judgment.
[0109] 2) Traversal and preliminary screening: For each encrypted data Enc(xi), compare it with each prime number a[i] in the prime number list in turn. Calculate whether the difference n - a[i] is zero by calling the shsign(n - a[i]) function. If it is zero, it means that n is a prime number in the prime number list. Accumulate all the results to get the k value. At the same time, calculate the difference between the encrypted ciphertext a of the number to be tested and the encrypted ciphertext b of any element in the prime number list, and call the shsign function to get the ciphertext value c.
[0110] 3) Dynamic assignment and greatest common divisor calculation: According to the ciphertext value c, dynamically adjust the values of the encrypted ciphertexts a and b to ensure that a is always greater than or equal to b. Then, use an improved greatest common divisor calculation method, including steps such as using an array d[i] to accelerate the iteration process, marking non-negativity, and finding the largest binary coefficient, to gradually narrow the gap between a and b until their greatest common divisor is found.
[0111] 4) Repeated calculation: For each prime number in the prime number list, repeat the above process. Finally, obtain max greatest common divisors. Accumulate and sum these max greatest common divisors to get the t value, and call the shsign function again to get the j value.
[0112] 5) Result determination: Finally, add k and j. If the sum is 1, the original value represented by the corresponding Enc(xi) is a prime number; if the sum is 0, the value is a composite number. The cloud platform returns the encrypted statistical information to the user, and the user can obtain the specific distribution of prime numbers in the dataset after decryption.
[0113] Through this embodiment, the primality testing method in the ciphertext state can not only effectively protect the user's private data, but also greatly improve the processing efficiency and avoid the high computational complexity problem brought by the traditional trial division method. Especially for big data analysis and algorithm optimization, its method of accurately judging prime numbers in the ciphertext state has important practical application value. It enables efficient data processing and analysis even in a highly sensitive data environment, further promoting the development of data privacy protection technology.
[0114] Embodiment 3;
[0115] As Figure 4 shown, this embodiment provides a primality testing system in the ciphertext state, including:
[0116] Initialization module: used to determine the array a[max] as the prime number list based on the primality testing range, and write the sign function shsign(x) in combination with the fully homomorphic encryption library;
[0117] Difference sign calculation and accumulation module: used to traverse the prime number list, use the difference n - a[i] between the number to be tested n and each prime number a[i] in the prime number list as a parameter to call the shsign function, store the result shsign(n - a[i]) in the array b[i], and accumulate and sum the array b[i] to get the result k;
[0118] Ciphertext difference sign calculation module: used to perform difference calculation on the encrypted ciphertext a of the number to be tested n and the encrypted ciphertext b of any element in the prime number list, and call the shsign function to get the ciphertext value c;
[0119] Greatest common divisor calculation module: used to dynamically assign values to the encrypted ciphertext a and the encrypted ciphertext b using the ciphertext value c, and calculate the greatest common divisor of the encrypted ciphertext a and the encrypted ciphertext b;
[0120] Greatest common divisor collection module: used to traverse all elements in the prime number list to obtain max greatest common divisors;
[0121] Greatest common divisor accumulation module: used to accumulate and sum the max greatest common divisors to get the result t, and call the shsign function to get the result j;
[0122] Prime property judgment module: used to add k and j, and complete the prime property test in the ciphertext state based on the addition result.
[0123] This embodiment provides a prime property test system in the ciphertext state, including an initialization module, a difference symbol calculation and accumulation module, a ciphertext difference symbol calculation module, a greatest common divisor calculation module, a greatest common divisor collection module, a greatest common divisor accumulation module, and a prime property judgment module. This system realizes efficient prime property testing without exposing the original data by pre-storing a prime number list and combining with the fully homomorphic encryption technology. It not only protects data privacy but also significantly improves processing efficiency.
[0124] Embodiment 4;
[0125] As Figure 5 shown, this embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the prime property test method in the ciphertext state in the above embodiment.
[0126] Embodiment 5;
[0127] This embodiment provides a computer-readable storage medium, and the storage medium stores a computer program. When the computer program is executed by a processor, it implements the prime property test method in the ciphertext state in the above embodiment.
[0128] In the above embodiments provided by the present application, it should be understood that the disclosed methods, systems, devices, and media can be implemented in other ways. The method, system, device, and media embodiments described above are only illustrative. For example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation. Each functional unit can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit.
[0129] Combined with the units and algorithm steps of each example described in the embodiments disclosed in this article, they can be implemented by electronic hardware, or by a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but this implementation should not be considered to exceed the scope of this application.
[0130] Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disc, computer memory, read-only memory, random access memory, electrical carrier signal, telecommunication signal, and software distribution medium, etc.
[0131] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A primality test method in a ciphertext state, characterized in that: The following steps are involved: S1. Based on the primality test range, the array a[max] is determined as the prime number list, and the symbol function shsign(x) is written in combination with the fully homomorphic encryption library. The symbol function shsign(x) is used to determine whether the plaintext value of the ciphertext x is equal to 0. If the plaintext value of the ciphertext x is equal to 0, the ciphertext of 1 is output, otherwise the ciphertext of 0 is output; S2. Traverse the prime number list, use the difference na[i] between the number to be tested n and each prime number a[i] in the prime number list as a parameter to call the shsign function, obtain the shsign(na[i]) result and store it in the array b[i], and accumulate and sum the array b[i] to obtain the result k; S3, calculate the difference between the encrypted ciphertext a of the number n to be tested and the encrypted ciphertext b of any element in the prime number list, and call the shsign function to obtain the ciphertext value c; S4. Use the ciphertext value c to dynamically assign values to the encrypted ciphertext a and the encrypted ciphertext b, and calculate the greatest common factor of the encrypted ciphertext a and the encrypted ciphertext b; The dynamic assignment includes: performing (1-c) * a + c * b assignment on a to ensure that the ciphertext a is a larger value; performing c* a + (1-c) * b assignment on b to ensure that the ciphertext b is a smaller value; The calculation of the greatest common factor of the encrypted ciphertext a and the encrypted ciphertext b includes: S41, store b*2 through array d[i] i , used to accelerate the iterative calculation of the greatest common factor; S42, using array c[i] to mark whether ad[i] is non-negative, and using array s[i] = c[i+1]-c[i] to mark whether d[i] is the largest binary coefficient less than a; S43, get the maximum binary coefficient by summing up the array t[i] = s[i] * d[i], and iteratively calculate ab*2 i The greatest common factor of a and b is output until the maximum number of iterations is reached; S5, repeat steps S3-S4 until all elements in the prime number list are traversed and max greatest common factors are obtained; S6, accumulating and summing the max greatest common divisors to obtain a result t, and calling the shsign function to obtain a result j; S7. Add k and j, and perform a primality test in the encrypted state based on the addition result. If the addition result is 1, n is a prime number; if the addition result is 0, n is a composite number.
2. The primality test method in a ciphertext state according to claim 1, characterized in that: In S1, determining the array a[max] as a prime number list based on the primality test range includes: If the primality test range is 2 m , then it will be less than or equal to All prime numbers are stored in array a[max] as a prime number list; where max represents the number of prime numbers stored.
3. The primality test method in a ciphertext state according to claim 1, characterized in that: In S43, the maximum number of iterations is: ; in, represents the ceiling function, It means taking the larger value of a and b.
4. A primality test system in a ciphertext state, characterized in that: include: Initialization module: used to determine the array a[max] as the prime number list based on the primality test range, and write the symbol function shsign(x) in combination with the fully homomorphic encryption library. The symbol function shsign(x) is used to determine whether the plaintext value of the ciphertext x is equal to 0. If the plaintext value of the ciphertext x is equal to 0, the ciphertext of 1 is output, otherwise the ciphertext of 0 is output; Difference sign calculation and accumulation module: used to traverse the prime number list, call the shsign function with the difference na[i] between the number to be tested n and each prime number a[i] in the prime number list as a parameter, obtain the shsign(na[i]) result and store it in the array b[i], and accumulate and sum the array b[i] to obtain the result k; Ciphertext difference sign calculation module: used to calculate the difference between the encrypted ciphertext a of the number n to be tested and the encrypted ciphertext b of any element in the prime number list, and call the shsign function to obtain the ciphertext value c; The greatest common factor calculation module is used to dynamically assign values to the encrypted ciphertext a and the encrypted ciphertext b using the ciphertext value c, and calculate the greatest common factor of the encrypted ciphertext a and the encrypted ciphertext b; The dynamic assignment includes: performing (1-c) * a + c * b assignment on a to ensure that the ciphertext a is a larger value; performing c* a + (1-c) * b assignment on b to ensure that the ciphertext b is a smaller value; The calculation of the greatest common factor of the encrypted ciphertext a and the encrypted ciphertext b includes: Store b*2 through array d[i] i , used to speed up iterative calculation of the greatest common factor; Use array c[i] to mark whether ad[i] is non-negative, and use array s[i] = c[i+1]-c[i] to mark whether d[i] is the largest binary coefficient less than a; The maximum binary coefficient is obtained by summing up the array t[i] = s[i] * d[i], and ab*2 is calculated iteratively i The greatest common factor of a and b is output until the maximum number of iterations is reached; Greatest common factor collection module: used to traverse all elements in the prime number list and obtain the max greatest common factors; The greatest common factor accumulation module is used to accumulate and sum the max greatest common factors to obtain the result t, and call the shsign function to obtain the result j; Primeness judgment module: used to add k and j, and complete the primality test in the ciphertext state based on the addition result. If the addition result is 1, n is a prime number; if the addition result is 0, n is a composite number.
5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the primality testing method in the encrypted state as described in any one of claims 1 to 3 is implemented.
6. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the primality testing method in a ciphertext state as described in any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
A public key encryption method supporting multi-keyword search against keyword guess attack
CN109086615A
Method and device for generating key of RSA encryption algorithm based on real-time passenger flow model
CN111130785A