Vexicity test method, system and equipment in ciphertext state and medium

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 and accurate prime quality testing, which is suitable for scenarios such as cloud computing that require high data confidentiality.

CN119814312AActive Publication Date: 2025-04-11BEIJING YINSUAN TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510251808.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-05
Publication Date
2025-04-11
Estimated Expiration
2045-03-05

AI Technical Summary

Technical Problem

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.

Method used

By combining all-homomorphic encryption technology and pre-stored prime number list, a primeness test method in the ciphertext state is designed, using the symbol function shsign(x) to judge the numerical size, and through dynamic adjustment mechanism and iterative calculation of the maximum common factor, efficient primeness test is achieved.

Benefits of technology

This method significantly reduces computational complexity and memory consumption, improves algorithm efficiency and accuracy, is suitable for large-scale data processing, and ensures data privacy and efficient computing performance in cloud computing environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119814312A_ABST
    Figure CN119814312A_ABST
Patent Text Reader

Abstract

The invention provides a prime test method, system and device in a ciphertext state and a medium. The method comprises the following steps: determining a prime number list and compiling a sign function; taking a difference value between the number to be tested and each prime number in the prime number list as a parameter to call a sign function, storing a result into an array b [i], and accumulating and summing to obtain a result k; performing difference calculation on the encrypted ciphertext a of the number to be measured and the encrypted ciphertext b of any element in the prime number list, and calling a sign function to obtain a ciphertext value c; performing dynamic assignment, and calculating a maximum common factor; traversing all elements to obtain max maximum common factors; accumulating and summing to obtain a result t, and calling a sign function to obtain a result j; k and j are added, and the primitive test in the ciphertext state is completed. According to the method, the prime test can be performed on the encrypted data in the ciphertext state, the data privacy is effectively protected, and the efficiency and the flexibility of encrypted data processing are improved by combining the prime number list and the maximum common factor calculation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data privacy protection, and more specifically to a primality testing method, system, device and medium in a 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 the Internet of Things, the amount of data has exploded, and the security and privacy of data have become the focus of people's attention.

[0003] Fully homomorphic encryption allows computing operations to be performed directly on encrypted data without exposing the original data content, providing a revolutionary solution to data privacy issues. However, in practical applications, traditional methods often fail to meet the needs, especially when complex operations such as primality testing are required.

[0004] The primality testing methods in the prior art mainly include direct methods and screening methods, but these methods all have significant defects. The direct method determines whether a number is prime by checking whether it can be divided by all numbers smaller than it. This method not only involves division operations that are difficult to implement in a homomorphic encryption environment, but also has high time complexity and is extremely inefficient for large-scale data sets or large numbers. On the other hand, although the screening method can effectively find all prime numbers within a certain range, it consumes huge memory and has high time complexity. In particular, it is inefficient when dealing with the primality judgment of a single large number, and is not suitable for application scenarios in the context of fully homomorphic encryption.

[0005] Furthermore, it cannot be directly applied to primality testing in ciphertext state. Due to the special properties of fully homomorphic encryption, traditional mathematical operations such as division and Boolean array operations are difficult to implement effectively, resulting in the inability of existing primality testing methods to provide efficient computing performance while ensuring data privacy. In addition, traditional methods lack the ability to directly operate on ciphertext data, which limits their application in scenarios that require high data confidentiality, such as cloud computing.

[0006] Therefore, how to design a primality test method in a ciphertext state that can overcome the high computational complexity and memory consumption problems existing in the prior art while ensuring data privacy, and at the same time support the direct execution of necessary mathematical operations on encrypted data is an issue that technical personnel in this field urgently need to solve. Summary of the invention

[0007] In view of this, the present invention provides a primality testing method in a ciphertext state, which can utilize the advantages of fully homomorphic encryption technology without exposing plaintext data to achieve fast primality testing of encrypted data, so as to meet the growing needs of data security and privacy protection, while improving the efficiency and flexibility of data processing.

[0008] In order to achieve the above object, the present invention adopts the following technical solution:

[0009] In a first aspect, the present invention provides a primality test method in a ciphertext state, comprising the following steps:

[0010] S1. Determine the array a[max] as the prime number list based on the primality test range, and write the sign function shsign(x) in combination with the fully homomorphic encryption library;

[0011] 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;

[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. 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;

[0014] S5, repeating steps S3-S4 until all elements in the prime number list are traversed to obtain max greatest common factors;

[0015] S6, accumulating and summing the max greatest common divisors to obtain a result t, and calling the shsign function to obtain a result j;

[0016] S7. Add k and j, and complete the primality test in the encrypted state based on the addition result.

[0017] Furthermore, in S1, determining the array a[max] as a prime number list based on the primality test range includes:

[0018] 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.

[0019] Furthermore, 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, then output the ciphertext of 1, otherwise output the ciphertext of 0.

[0020] Furthermore, in S4, the encrypted ciphertext a and the encrypted ciphertext b are dynamically assigned using the ciphertext value c, including:

[0021] Assign a (1-c) * a + c * b to ensure that the ciphertext a is a larger value;

[0022] Assign c * a + (1-c) * b to b to ensure that the ciphertext b is a smaller value.

[0023] Furthermore, in S4, calculating the greatest common factor of the encrypted ciphertext a and the encrypted ciphertext b includes:

[0024] S41, store b*2 through array d[i] i , used to accelerate the iterative calculation of the greatest common factor;

[0025] 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;

[0026] 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 divisor of a and b is output until the maximum number of iterations is reached.

[0027] Furthermore, in S43, the maximum number of iterations is:

[0028]

[0029] in, represents the ceiling function, It means taking the larger value of a and b.

[0030] Furthermore, in S7, a primality test in the encrypted ciphertext state is performed based on the addition result, including: if the addition result is 1, n is a prime number, and if the addition result is 0, n is a composite number.

[0031] In a second aspect, the present invention provides a primality testing system in a ciphertext state, comprising:

[0032] Initialization module: used to determine the array a[max] as a prime number list based on the primality test range, and write the sign function shsign(x) in combination with the fully homomorphic encryption library;

[0033] 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;

[0034] 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;

[0035] 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;

[0036] Greatest common factor collection module: used to traverse all elements in the prime number list and obtain the max greatest common factors;

[0037] 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;

[0038] Primeness judgment module: used to add k and j, and complete the primality test in the encrypted state based on the addition result.

[0039] In a third aspect, the present invention provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned primality test method in a encrypted state when executing the computer program.

[0040] In a fourth aspect, the present invention provides a computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the primality test method in the encrypted state is implemented.

[0041] The descriptions of the second to fourth aspects of the present invention can refer to the detailed description of the first aspect; and the beneficial effects of the descriptions of the second to fourth aspects can refer to the analysis of the beneficial effects of the first aspect, which will not be repeated here.

[0042] It can be seen from the above technical solution that compared with the prior art, the present invention has the following beneficial effects:

[0043] 1. This method uses fully homomorphic encryption and a pre-stored prime number list to achieve efficient primality testing of large numbers in ciphertext. Compared with the traditional direct method and screening method, it avoids the need to directly perform division operations, greatly reduces computational complexity, and reduces memory consumption. By using the sign function shsign(x) to determine the value size, the efficiency and accuracy of the algorithm are further improved, making it more feasible when processing large-scale data.

[0044] 2. It also combines a dynamic adjustment mechanism to automatically adjust the values ​​of the encrypted ciphertext a and b according to different numbers to be tested n to ensure the accuracy and efficiency of the greatest common factor calculation. In addition, by iteratively calculating and gradually narrowing the range until the greatest common factor of two numbers is found, it is not only applicable to numbers of a certain size, but can also be extended to a larger range of primality tests. It can maintain good performance for both small and large 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. With fully homomorphic encryption, users can safely 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 a high degree of data confidentiality (such as finance, medical care, etc.), and can effectively prevent sensitive information from being obtained by unauthorized third parties. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0047] Figure 1 A flow chart of a primality testing method in a ciphertext state provided by an embodiment of the present invention;

[0048] Figure 2 A schematic diagram of a process for calculating the greatest common divisor of encrypted ciphertext a and encrypted ciphertext b provided in an embodiment of the present invention;

[0049] Figure 3 A schematic diagram of a primality test implementation process provided by an embodiment of the present invention;

[0050] Figure 4 A framework diagram of a primality testing system in a ciphertext state provided by an embodiment of the present invention;

[0051] Figure 5 A schematic diagram of the structure of an electronic device is provided for an embodiment of the present invention. DETAILED DESCRIPTION

[0052] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0053] The primality testing method provided in the embodiment of the present application can be applied to a primality testing server, and the primality testing server can be hardware or software. When the primality testing server is hardware, it can be implemented as a distributed server cluster that provides primality testing services, or it can be implemented as a single server. When the primality testing server is software, it can be installed in the servers listed above. It can be implemented as multiple software or software modules, or it can be implemented as a single software or software module, which is not specifically limited here.

[0054] Embodiment 1;

[0055] like Figure 1 As shown, this embodiment provides a primality test method in a ciphertext state, comprising the following steps:

[0056] S1. Determine the array a[max] as the prime number list based on the primality test range, and write the sign function shsign(x) in combination with the fully homomorphic encryption library;

[0057] 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;

[0058] 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;

[0059] 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;

[0060] S5, repeating steps S3-S4 until all elements in the prime number list are traversed to obtain max greatest common factors;

[0061] S6, accumulating and summing the max greatest common divisors to obtain a result t, and calling the shsign function to obtain a result j;

[0062] S7. Add k and j, and complete the primality test in the encrypted state based on the addition result.

[0063] This method combines fully homomorphic encryption and primality testing algorithms to efficiently determine prime numbers in ciphertext, avoiding the problems of division operations and high memory consumption in traditional methods. Its core advantage is that it significantly improves computing efficiency by pre-storing prime number lists and optimizing the calculation of the greatest common factor, while ensuring data privacy, making it suitable for cloud computing and other scenarios where data security needs to be protected.

[0064] The following is a further detailed description of each step in the above method:

[0065] In this embodiment S1, the array a[max] is determined as a prime number list based on the primality test range, and the sign function shsign(x) is written in combination with the fully homomorphic encryption library;

[0066] Among them, 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.

[0067] According to the trial division method, we can determine whether n is a prime number by traversing to the square root of n. This can be proved by contradiction: assuming that traversing to the square root of n still cannot determine whether n is a prime number, then there exist natural numbers a and b such that n=a*b, and 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 hypothesis; if a and b are both greater than the square root of n, then a*b>n, which also contradicts the hypothesis. Therefore, the proof is established.

[0068] Here, it is determined that 2 14 Taking the data n in the figure as an example to determine whether it is a prime number, the determination of the prime number list is further explained. Since the prime number can be determined by judging whether the square root of n is a prime number, when determining the prime number, it is only necessary to store the prime number list less than 2. 7 There are 31 prime numbers (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). The maximum number of prime numbers stored is 31.

[0069] The above-mentioned 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, then output the ciphertext of 1, otherwise output the ciphertext of 0.

[0070] Further, the prime number list is traversed, and the difference na[i] between the number to be tested n and each prime number a[i] in the prime number list is used as a parameter to call the shsign function, and the result of shsign(na[i]) is stored in the array b[i], and the array b[i] is accumulated and summed to obtain the result k;

[0071] Furthermore, the encrypted ciphertext a of the number n to be tested is calculated to be different from the encrypted ciphertext b of any element in the prime number list, and the shsign function is called to obtain the ciphertext value c;

[0072] Furthermore, the encrypted ciphertext a and the encrypted ciphertext b are dynamically assigned using the ciphertext value c, and the greatest common factor of the encrypted ciphertext a and the encrypted ciphertext b is calculated; wherein the encrypted ciphertext a and the encrypted ciphertext b are dynamically assigned using the ciphertext value c, including:

[0073] Assign (1-c) * a + c * b to a to ensure that the ciphertext a is a larger value; assign c * a + (1-c) *b to b to ensure that the ciphertext b is a smaller value.

[0074] Here, the encrypted ciphertext a and b are dynamically assigned by the ciphertext value c, ensuring that a is always a larger value and b is a smaller value in each iteration. Specifically, (1-c)*a+c*b is assigned to a, and c*a+(1-c)*b is assigned to b, and the value of c (in ciphertext form of 0 or 1) is used to control the size relationship between a and b. This dynamic assignment mechanism ensures that when calculating the greatest common divisor, the values ​​of a and b can gradually converge, thereby efficiently completing the GCD calculation in the ciphertext state, while avoiding the risk of plaintext exposure.

[0075] Further, such as Figure 2 As shown, calculating the greatest common factor of the encrypted ciphertext a and the encrypted ciphertext b includes:

[0076] S41, store b*2 through array d[i] i , used to accelerate the iterative calculation of the greatest common factor;

[0077] 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;

[0078] 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 divisor of a and b is output until the maximum number of iterations is reached.

[0079] The following is a further explanation of each array here in combination with the value of i. For array d[i], in order to ensure that array d[i] contains enough elements to cover the possible iteration range, the value of i needs to be set from 0 to the maximum value max. Therefore, the loop condition is set to i=0; i≤max; i++; so that array d will contain max+1 elements; since array d[i] has max+1 elements, after performing the shsign operation on each d[i], array c[i] will have max+1 corresponding results.

[0080] In practical applications, in order to ensure that the largest b*2 that is just less than a can be correctly calculated i , the last element in the array c[i] needs to be ignored, and the last element (corresponding to i=max) is not directly used in the calculation of the greatest common factor. Therefore, when calculating s[i] and t[i], the loop conditions are set to i=0; i≤max-1; i++; s[i] and t[i] will both contain max elements.

[0081] Furthermore, the calculation of the greatest common factor of a and b through iterative operation is further described through the following implementation process:

[0082] The input parameters include: a=1023, b=1, max_size=20 represents the maximum index of the array, and max=10 represents the maximum index value actually used in this implementation. Array definition and initialization include: d[i] is initialized to an array from 1 to 1024, c[i] is initialized to an array from 0 to 1, s[i] is initialized to an array from 0 to 1, and t[i] is initialized to an array from 0 to 512.

[0083] The iteration 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, the initial values ​​are a=1023, b=1, the largest non-zero element in t[i] is found to be 512, and a=a-512=511 is updated.

[0085] In the second iteration, the updated values ​​are a=511, b=1, the largest non-zero element in t[i] is found to be 256, and a=a-256=255 is updated.

[0086] In subsequent iterations, the above process is repeated, gradually reducing the value of a: the third iteration a=255-128=127, the fourth iteration a=127-64=63, the fifth iteration a=63-32=31, the sixth iteration a=31-16=15, the seventh iteration a=15-8=7, the eighth iteration a=7-4=3, the ninth iteration a=3-2=1, and the tenth iteration a=1-1=0; the final 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, the gap between a and b is gradually reduced, and the greatest common factor of a and b is eventually found.

[0088] Furthermore, the maximum number of iterations is:

[0089]

[0090] in, represents the ceiling function, It means taking the larger value of a and b.

[0091] Here, the maximum number of iterations is further explained. In the first iteration, there are two possible situations:

[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 range of a and b is significantly reduced because the value of a is at least reduced by more than half of its original value.

[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 larger than a / 2; in this case, the range of a and b is not reduced significantly, because b is still close to a / 2. However, since the encrypted ciphertext a and the encrypted ciphertext b are dynamically assigned using the ciphertext value c during each iteration, ensuring that a>b, then there must be a / 2>b / 2, and at this time there must be a>b>a / 2>b / 2, so after the second iteration, it is guaranteed to be reduced to more than half of the original.

[0094] In summary, since the range is at least reduced to half of the original after each iteration, the maximum number of iterations set here can ensure that the calculation is completed within a limited number of iterations; in this way, the algorithm can efficiently calculate the greatest common factor under ciphertext, and thus realize the judgment of prime numbers.

[0095] Furthermore, the above steps are repeated until all elements in the prime number list are traversed to obtain the max greatest common factors;

[0096] Further, the max greatest common factors are accumulated and summed to obtain a result t, and the shsign function is called to obtain a result j;

[0097] Add k and j, and complete the primality test in the encrypted state based on the addition result, including: if the addition result is 1, n is a prime number, and if the addition result is 0, n is a composite number.

[0098] The following is a further detailed description of k and j based on different situations 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 in the range greater than the prime number list), j+k=1, n is determined to be 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 factor with some numbers in the prime number list is not 1), j+k=0, n is determined to be 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 factor with each number in the prime number list is 1), j+k=1, n is determined to be 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 factor with some numbers in the prime number list is not 1), j+k=0, n is determined to be a composite number.

[0100] The four cases of n and the output results are shown in the following table:

[0101] n case The first result k The second result k+j Prime numbers smaller than the list of prime numbers 1 0 1 Composite numbers smaller than the list of prime numbers 0 0 0 Prime numbers greater than the prime list 0 1 1 Composite numbers greater than the list of prime numbers 0 0 0

[0102] Therefore, through the result of j+k, we can determine 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 a ciphertext state. By predefining a prime number list, combining the symbolic function in fully homomorphic encryption technology, and dynamically calculating the greatest common divisor, it is possible to efficiently determine whether the number to be tested is a prime number without decrypting the data, effectively protecting data privacy and significantly improving computing efficiency. The method can be widely used in 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, but for the sake of privacy protection, they do not want to directly expose the original data. For example, when optimizing encryption algorithm parameters, it is very valuable to understand the distribution of prime numbers in the data set. This embodiment shows how to use the above-mentioned primality test method in the ciphertext state to help users count the distribution of prime numbers in the encrypted data set without leaking the data content.

[0106] Specifically, the user has a data set containing 10,000 integers and wants to use cloud services to count the number of prime numbers in it in order to optimize the parameters of its encryption algorithm. In order to protect data privacy, the user first uses fully homomorphic encryption technology to encrypt the data set and generate a set of encrypted data {Enc(x1), Enc(x2), ..., Enc(x10000)}. Then upload these encrypted data to the cloud platform and use the cloud service to perform primality tests in the ciphertext state.

[0107] like Figure 3 As shown in Figure 2, the specific primality test implementation process includes:

[0108] 1) Initialization phase: Based on the primality test range provided by the user, determine a pre-stored prime number list a[max], assuming m=214, then it is necessary to store a prime number less than or equal to All prime numbers in are taken as prime number list. At the same time, the sign function shsign(x) is written 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 na[i] is zero by calling the shsign(na[i]) function. If it is zero, it means that n is a prime number in the prime number list. All results are accumulated to get the value k. 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 factor calculation: According to the ciphertext value c, the values ​​of the encrypted ciphertexts a and b are dynamically adjusted to ensure that a is always greater than or equal to b. Then, an improved greatest common factor calculation method is used, including using the array d[i] to speed up the iteration process, marking non-negativity and finding the maximum binary coefficient, etc., to gradually narrow the gap between a and b until their greatest common factor is found.

[0111] 4) Repeat the calculation: Repeat the above process for each prime number in the prime number list, and finally get the max greatest common factors. Add up these max greatest common factors 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 result is 1, the original value represented by the corresponding Enc(xi) is a prime number; if the result is 0, the value is a composite number. The cloud platform returns the encrypted statistical information to the user, who can obtain the specific distribution of prime numbers in the data set after decryption.

[0113] Through this embodiment, the primality test method in the encrypted state can not only effectively protect the user's privacy data, but also greatly improve the processing efficiency and avoid the high computational complexity problem caused by the traditional trial division method. In particular, for big data analysis and algorithm optimization, the method of accurately judging prime numbers in the encrypted state has important practical application value. It enables efficient data processing and analysis even in highly sensitive data environments, further promoting the development of data privacy protection technology.

[0114] Embodiment 3;

[0115] like Figure 4 As shown, this embodiment provides a primality test system in a ciphertext state, including:

[0116] Initialization module: used to determine the array a[max] as a prime number list based on the primality test 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, 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;

[0118] 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;

[0119] 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;

[0120] Greatest common factor collection module: used to traverse all elements in the prime number list and obtain the max greatest common factors;

[0121] 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;

[0122] Primeness judgment module: used to add k and j, and complete the primality test in the encrypted state based on the addition result.

[0123] This embodiment provides a primality test system in a ciphertext state, including an initialization module, a difference symbol calculation and accumulation module, a ciphertext difference symbol calculation module, a greatest common factor calculation module, a greatest common factor collection module, a greatest common factor accumulation module, and a primality judgment module. The system pre-stores a prime number list and combines it with fully homomorphic encryption technology to achieve efficient primality testing without exposing the original data, which not only protects data privacy, but also significantly improves processing efficiency.

[0124] Embodiment 4;

[0125] like Figure 5 As 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, wherein the processor implements the primality test method in the encrypted state in the above embodiment when executing the computer program.

[0126] Embodiment 5;

[0127] This embodiment provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the primality test method in the encrypted state in the above embodiment is implemented.

[0128] In the above embodiments provided in the present application, it should be understood that the disclosed methods, systems, devices and media can be implemented in other ways. The above described methods, systems, devices and media embodiments are only schematic. 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 into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0129] The units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0130] The computer program includes computer program code, which may be in source code form, object code form, executable file or some intermediate form, etc. Computer readable media may include: any entity or device capable of carrying computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory, random access memory, electric 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 aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions 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. Determine the array a[max] as the prime number list based on the primality test range, and write the sign function shsign(x) in combination with the fully homomorphic encryption library; 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; S5, repeating steps S3-S4 until all elements in the prime number list are traversed to obtain max greatest common factors; 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 complete the primality test in the encrypted state based on the addition result.

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 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, then output the ciphertext of 1, otherwise output the ciphertext of 0.

4. The primality test method in a ciphertext state according to claim 1, characterized in that: In S4, the encrypted ciphertext a and the encrypted ciphertext b are dynamically assigned using the ciphertext value c, including: Assign a (1-c) * a + c * b to ensure that the ciphertext a is a larger value; Assign c * a + (1-c) * b to b to ensure that the ciphertext b is a smaller value.

5. The primality test method in a ciphertext state according to claim 1, characterized in that: In S4, calculating 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, obtain the maximum binary coefficient by summing up the array t[i] = s[i] * d[i], and iteratively calculate ab*2 i The greatest common divisor of a and b is output until the maximum number of iterations is reached.

6. The primality test method in a ciphertext state according to claim 5, 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.

7. The primality test method in a ciphertext state according to claim 1, characterized in that: In S7, a primality test in the encrypted ciphertext state is performed based on the addition result, including: if the addition result is 1, n is a prime number, and if the addition result is 0, n is a composite number.

8. A primality test system in a ciphertext state, characterized in that: include: Initialization module: used to determine the array a[max] as a prime number list based on the primality test range, and write the sign function shsign(x) in combination with the fully homomorphic encryption library; 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; 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 encrypted state based on the addition result.

9. 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 7 is implemented.

10. 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 7 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

  • Distributed primitive test method, device and system

    CN114697034A

  • Resource synchronization coordination method and system based on fully homomorphic encryption

    CN119182510A

  • Device, system, and method of generating and handling cryptographic parameters

    US20210226783A1