A ciphertext k-nearest neighbor classification method based on homomorphic encryption

By using fully homomorphic encryption technology to perform K-nearest neighbor classification within the ciphertext domain, the problem of sensitive data leakage in cloud computing is solved, achieving efficient and accurate classification results and privacy protection.

CN121479490BActive Publication Date: 2026-04-21BEIJING YINSUAN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING YINSUAN TECH CO LTD
Filing Date
2026-01-12
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

In cloud computing environments, traditional K-nearest neighbor classification algorithms require plaintext data operations, which can lead to the leakage of sensitive information. Existing technologies are unable to efficiently and accurately complete ciphertext distance calculation, sorting, and classification under fully homomorphic encryption, and cannot meet the real-time processing needs of large-scale data.

Method used

The training and test samples are encrypted using fully homomorphic encryption technology. The ciphertext position values ​​are sorted by calculating the Euclidean distance in the ciphertext domain, sorting the ciphertext, and making classification decisions. The client decrypts the ciphertext and determines the final category.

Benefits of technology

While ensuring data privacy, it achieves both accuracy and efficiency in encrypted K-nearest neighbor classification, adapts to the needs of large-scale data processing, prevents data leakage, and maintains classification accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121479490B_ABST
    Figure CN121479490B_ABST
Patent Text Reader

Abstract

This invention discloses a ciphertext K-nearest neighbor classification method based on fully homomorphic encryption, relating to the fields of data security and privacy computing. The method includes: acquiring a training sample set with known categories, preprocessing and performing fully homomorphic encryption to generate a ciphertext training set; performing fully homomorphic encryption on the client side on the feature vectors of the samples to be classified to generate ciphertext test samples; calculating the Euclidean distance between the ciphertext test samples and each training sample in the ciphertext training set to obtain a set of ciphertext distances; selecting the K smallest ciphertext distances using a ciphertext sorting algorithm; subtracting each ciphertext distance from each ciphertext distance in the ciphertext distance set, and packaging it with the category label of the corresponding training sample; and determining the final category of the sample to be classified based on the difference information after decryption on the client side. By performing K-nearest neighbor classification operations in a fully ciphertext state, it can obtain accurate classification results consistent with plaintext calculations while ensuring that the privacy of the original data is not leaked.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data security and privacy computing, and more specifically to a ciphertext K-nearest neighbor classification method based on fully homomorphic encryption. Background Technology

[0002] With the deep integration of cloud computing and artificial intelligence, various organizations often outsource data containing sensitive information to third-party platforms for processing and analysis. Ensuring that data privacy is not leaked has become a core challenge in practical application scenarios such as intelligent identity recognition, product recommendation, and anomaly detection.

[0003] The core operation of the traditional K-nearest neighbor classification algorithm must be performed directly on the plaintext values ​​of the sample features. When the data owner encrypts the data and uploads it to the cloud server to protect privacy, the server cannot directly perform the classification task. If the server is required to perform the calculation, it must be provided with the decryption key or the data owner must decrypt the data. This essentially undermines the privacy and security premise of data outsourcing, causing the user's sensitive raw data to be exposed in the cloud.

[0004] To mitigate privacy breaches, existing technologies have proposed several alternatives, each with significant limitations. For instance, differential privacy techniques inject noise into the data to obscure individual information, but inevitably distort the original data distribution, leading to inaccurate distance calculations and reducing the final accuracy and reliability of the K-nearest neighbor classification model. While cryptographic schemes such as secure multi-party computation can guarantee accuracy, they typically involve multiple rounds of frequent interactive communication and complex protocol coordination. When comparing and ranking the distances of a large number of samples, they introduce extremely high communication overhead and computational latency, making them unsuitable for large-scale cloud processing scenarios.

[0005] Although fully homomorphic encryption theoretically allows arbitrary computation on ciphertext data, making it possible to execute the K-nearest neighbor algorithm in an encrypted state, it still faces key bottlenecks in practical applications. Specifically, K-nearest neighbor classification not only requires support for addition and multiplication in ciphertext to complete distance calculations, but more importantly, it requires a secure mechanism that can efficiently and accurately compare, sort, and select the K smallest distance values ​​within the ciphertext domain. In this core aspect, there is often a lack of feasible solutions, or although they can be implemented, they are extremely inefficient and cannot meet the needs of actual business for real-time or near-real-time processing of large-scale data.

[0006] Therefore, how to design a ciphertext K-nearest neighbor classification method based on fully homomorphic encryption that can efficiently and accurately complete core operations, including distance comparison and sorting, in a fully ciphertext state, thereby providing excellent classification performance and practical efficiency while ensuring data privacy, is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0007] In view of this, the present invention provides a ciphertext K-nearest neighbor classification method based on fully homomorphic encryption, which aims to solve the security risk of sensitive information leakage caused by the need to operate on plaintext data in outsourced computing scenarios such as cloud computing. This allows data owners to complete complex K-nearest neighbor classification calculations with the help of the server after encrypting the data and uploading it to an untrusted server, and finally obtain the correct classification results, thereby achieving the goal of secure computing where data is usable but invisible.

[0008] To achieve the above objectives, the present invention adopts the following technical solution:

[0009] A ciphertext K-nearest neighbor classification method based on fully homomorphic encryption includes the following steps:

[0010] S1. Obtain the training sample set of known categories, preprocess the feature vector of each sample and perform fully homomorphic encryption to generate the ciphertext training set;

[0011] S2. The feature vectors of the samples to be classified are fully homomorphically encrypted on the client side to generate ciphertext test samples;

[0012] S3. Calculate the Euclidean distance between the ciphertext test sample and each training sample in the ciphertext training set to obtain the ciphertext distance set;

[0013] S4. Based on the ciphertext distance set, select the K ciphertext distances with the smallest distances using a ciphertext sorting algorithm to generate a set of K nearest neighbor ciphertext distances.

[0014] S5. Subtract each ciphertext distance in the ciphertext K nearest neighbor distance set from each ciphertext distance set to generate difference information, and package the difference information with the category label of the corresponding training sample to generate a ciphertext package set.

[0015] S6. The encrypted package is returned to the client. After decryption, the client determines the final category of the sample to be classified based on the difference information.

[0016] Preferably, S1 includes:

[0017] Obtain the training sample set , For the first The feature vector of each sample For the corresponding category label;

[0018] For the feature vector of each training sample Preprocessing is performed, including normalization and missing value imputation;

[0019] Each preprocessed feature vector is encrypted using a fully homomorphic encryption algorithm. Encryption is performed to obtain the ciphertext training vector. Constructing a ciphertext training set .

[0020] Preferably, S2 includes:

[0021] Extract the feature vector x of the sample to be classified;

[0022] The feature vector x is encrypted on the client side using a fully homomorphic encryption algorithm to obtain the ciphertext test sample. .

[0023] Preferably, S3 includes:

[0024] For each ciphertext training vector in the ciphertext training set Calculate its relationship with the ciphertext test sample in the ciphertext state. Euclidean distance The ciphertext distance set is obtained. The Euclidean distance Represented as:

[0025]

[0026] in, Representing ciphertext training vectors The j-th component, Indicates encrypted test sample The j-th component.

[0027] Preferably, S4 includes:

[0028] S41, Based on Ciphertext Distance Set The ciphertext position value is calculated for each ciphertext distance using a ciphertext comparison function;

[0029] S42. Using the ciphertext position values, and through a sorting mapping function based on the Lagrange interpolation polynomial, select the K nearest neighbor distances with the smallest ciphertext position values ​​to generate a set of K nearest neighbor distances for the ciphertext. .

[0030] Preferably, S41 includes:

[0031] Define ciphertext comparison function Used to compare two ciphertext values and Size:

[0032]

[0033] in, Represents a symbolic function, and when hour, The corresponding plaintext result is 1, otherwise it is 1. ;

[0034] For the ciphertext distance corresponding to the i-th training sample Calculate its ciphertext position value :

[0035]

[0036] in, , Let i and j represent the ciphertext distances corresponding to the i-th and j-th training samples, respectively. The plaintext value represents the position number of the ciphertext distance in ascending order.

[0037] Preferably, S42 includes:

[0038] Define the sequence of feature vectors of the encrypted training samples as { , ,…, The corresponding ciphertext position value sequence is { , ,…, } and the target location set T={1,2,…,N};

[0039] For each target sorting position k∈{1,2,…,K}, calculate the feature vector of the ciphertext sample sorted at the k-th position. :

[0040]

[0041]

[0042] in, For indicator-type basis functions, the following condition is met: if and only if the ciphertext position value The corresponding plaintext position value is equal to hour, The corresponding plaintext result is 1, otherwise it is 0; Let T represent the set obtained by removing element k from set T, where t is the set to be traversed. A loop variable containing all elements.

[0043] Preferably, S5 includes:

[0044] Set the nearest neighbor distances of the ciphertext K. Distance of each ciphertext in The distance sets between each ciphertext and the ciphertext are respectively Distance of each ciphertext in Subtraction is performed in the encrypted state to generate the difference information. and each difference information Category labels of corresponding training samples Packaging, generating a ciphertext package collection .

[0045] Preferably, S6 includes:

[0046] Pack the ciphertext into a set Send back to the client;

[0047] The client uses the same private key as the encryption key for each difference in the set. Decrypt;

[0048] Calculate the category label corresponding to the zero difference among all decryption results, and take the category that appears most frequently as the final classification result for the sample to be classified. :

[0049]

[0050] in, This represents a set of category labels, where c represents one of the categories. This indicates an indicator function that returns 1 when a condition is met and 0 otherwise. This indicates the corresponding decryption function.

[0051] Preferably, the fully homomorphic encryption employs a lattice-based fully homomorphic encryption algorithm or a modular component-based fully homomorphic encryption algorithm, supporting homomorphic operations of addition and multiplication.

[0052] As can be seen from the above technical solution, compared with the prior art, the technical solution of the present invention has the following beneficial effects:

[0053] 1. This scheme uses fully homomorphic encryption on the client side for training samples and samples to be classified, and performs Euclidean distance calculation, K-nearest neighbor sorting and classification decision directly on the server side in encrypted form. This ensures that sensitive data exists in encrypted form throughout the entire lifecycle of transmission, storage and processing, effectively preventing third-party computing platforms from snooping on and leaking the original plaintext data, and meeting the core security requirement of data being usable but not visible in privacy-sensitive scenarios.

[0054] 2. It utilizes the mathematical homomorphic properties of fully homomorphic encryption, ensuring that the decryption results of vector operations, comparisons, and sorting operations performed on ciphertext are consistent with the results of performing the traditional K-nearest neighbor algorithm on plaintext data. This overcomes the shortcomings of methods such as differential privacy, which suffer from decreased model accuracy due to added noise. While providing strong privacy protection, it ensures the correctness and reliability of classification decision results.

[0055] 3. By deploying the computationally intensive distance calculation and sorting process on the server's encrypted domain, and only retaining the necessary key management and final decryption steps on the client, this architecture not only reduces the client's computational and communication burden, but also adapts to the processing needs of large-scale training data in a cloud computing environment by supporting batch encryption and vectorized computation, providing a feasible implementation path for privacy-preserving intelligent classification. Attached Figure Description

[0056] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0057] Figure 1 A flowchart of a ciphertext K-nearest neighbor classification method based on fully homomorphic encryption is provided for an embodiment of the present invention;

[0058] Figure 2 This is a schematic diagram illustrating the process of generating the K-nearest neighbor distance set for ciphertext provided in an embodiment of the present invention. Detailed Implementation

[0059] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0060] like Figure 1 As shown, this embodiment provides a ciphertext K-nearest neighbor classification method based on fully homomorphic encryption, including the following steps:

[0061] S1. Obtain the training sample set of known categories, preprocess the feature vector of each sample and perform fully homomorphic encryption to generate the ciphertext training set;

[0062] S2. The feature vectors of the samples to be classified are fully homomorphically encrypted on the client side to generate ciphertext test samples;

[0063] S3. Calculate the Euclidean distance between the ciphertext test sample and each training sample in the ciphertext training set to obtain the ciphertext distance set;

[0064] S4. Based on the ciphertext distance set, select the K ciphertext distances with the smallest distances using a ciphertext sorting algorithm to generate a set of K nearest neighbor ciphertext distances.

[0065] S5. Subtract each ciphertext distance in the ciphertext K nearest neighbor distance set from each ciphertext distance set to generate difference information, and package the difference information with the category label of the corresponding training sample to generate a ciphertext package set.

[0066] S6. The encrypted package is returned to the client. After decryption, the client determines the final category of the sample to be classified based on the difference information.

[0067] This method directly performs Euclidean distance calculation, ranking comparison, and category decision-making required for K-nearest neighbor classification within a fully homomorphically encrypted ciphertext domain, effectively preventing privacy leaks of data on third-party computing platforms. Simultaneously, by leveraging the mathematical homomorphism of the encryption algorithm, the correctness of the ciphertext calculation results is guaranteed, resulting in final classification accuracy comparable to traditional plaintext K-nearest neighbor algorithms. Furthermore, its client-side encryption and server-side ciphertext calculation architecture provides a secure, reliable, and feasible technical path for privacy-preserving classification tasks involving large-scale sensitive data in cloud computing environments.

[0068] The following provides a further detailed explanation of each step and related feature in the above scheme;

[0069] In this embodiment, S1 involves obtaining a training sample set of known categories, preprocessing and fully homomorphically encrypting the feature vector of each sample to generate a ciphertext training set; including:

[0070] Obtain the training sample set , For the first The feature vector of each sample For the corresponding category label;

[0071] For the feature vector of each training sample Preprocessing is performed, including normalization and missing value imputation;

[0072] Each preprocessed feature vector is encrypted using a fully homomorphic encryption algorithm. Encryption is performed to obtain the ciphertext training vector. Constructing a ciphertext training set .

[0073] In this embodiment, S2, the feature vector of the sample to be classified is fully homomorphically encrypted on the client side to generate a ciphertext test sample; including:

[0074] Extract the feature vector x of the sample to be classified;

[0075] The feature vector x is encrypted on the client side using a fully homomorphic encryption algorithm to obtain the ciphertext test sample. .

[0076] In this embodiment, the fully homomorphic encryption uses a lattice-based fully homomorphic encryption algorithm or a modular component-based fully homomorphic encryption algorithm, supporting homomorphic operations of addition and multiplication;

[0077] Specifically, it refers to algorithms constructed based on lattice-hard problems (such as LWE and RLWE) or fully homomorphic encryption algorithms constructed based on modulo components such as the Chinese Remainder Theorem. These algorithms can directly perform any number of addition and multiplication homomorphic operations on ciphertext data without decryption. They can sequentially and correctly complete a series of complex operations such as Euclidean distance calculation, comparison sorting, and classification decision in the ciphertext domain, ensuring the feasibility and correctness of the entire K-nearest neighbor classification process in the encrypted state.

[0078] In this embodiment, S3 involves calculating the Euclidean distance between the ciphertext test sample and each training sample in the ciphertext training set to obtain the ciphertext distance set; S3 includes:

[0079] For each ciphertext training vector in the ciphertext training set Calculate its relationship with the ciphertext test sample in the ciphertext state. Euclidean distance The ciphertext distance set is obtained. The Euclidean distance Represented as:

[0080]

[0081] in, Representing ciphertext training vectors The j-th component, Indicates encrypted test sample The j-th component.

[0082] In this embodiment, S4, based on the ciphertext distance set, the K ciphertext distances with the smallest distances are selected using a ciphertext sorting algorithm to generate a ciphertext K nearest neighbor distance set; as follows: Figure 2 As shown, it includes:

[0083] S41, Based on Ciphertext Distance Set The ciphertext position value is calculated for each ciphertext distance using a ciphertext comparison function;

[0084] S42. Using the ciphertext position values, and through a sorting mapping function based on the Lagrange interpolation polynomial, select the K nearest neighbor distances with the smallest ciphertext position values ​​to generate a set of K nearest neighbor distances for the ciphertext. .

[0085] Furthermore, S41 includes:

[0086] Define ciphertext comparison function Used to compare two ciphertext values and Size:

[0087]

[0088] in, Represents a symbolic function, and when hour, The corresponding plaintext result is 1, otherwise it is 1. ;

[0089] In the ciphertext field, because fully homomorphic encryption algorithms only support a finite number of addition and multiplication homomorphic operations, they cannot directly compute non-continuous, non-polynomial sign functions. Therefore, it is necessary to use function approximation techniques to pre-design a high-order polynomial (such as a cubic polynomial). To approximate simulation The behavior of the function is determined by the fixed coefficients of the polynomial through numerical approximation, ensuring that within the expected range of the input value, the output of the polynomial can approximate the output of the sign function with an acceptable error. When the input is greater than zero, the output approaches 1, and when it is less than zero, the output approaches 0, thereby realizing the comparison and determination of the numerical magnitude in the encrypted state.

[0090] For the ciphertext distance corresponding to the i-th training sample Calculate its ciphertext position value :

[0091]

[0092] in, , Let i and j represent the ciphertext distances corresponding to the i-th and j-th training samples, respectively. The plaintext value represents the position number of the ciphertext distance in ascending order.

[0093] Furthermore, S42 includes:

[0094] Define the sequence of feature vectors of the encrypted training samples as { , ,…, The corresponding ciphertext position value sequence is { , ,…, } and the target location set T={1,2,…,N};

[0095] For each target sorting position k∈{1,2,…,K}, calculate the feature vector of the ciphertext sample sorted at the k-th position. :

[0096]

[0097]

[0098] in, For indicator-type basis functions, the following condition is met: if and only if the ciphertext position value The corresponding plaintext position value is equal to hour, The corresponding plaintext result is 1, otherwise it is 0; Let T represent the set obtained by removing element k from set T, where t is the set to be traversed. A loop variable containing all elements;

[0099] Specifically, define a Lagrange interpolation polynomial such that :

[0100]

[0101]

[0102] These are basis functions in Lagrange interpolation, and they have the following properties: ;

[0103] To ensure that P(k) is evaluated only when When the corresponding term is non-zero, an indicator basis function is introduced:

[0104]

[0105] Among them when When the numerator and denominator are exactly the same, the result is 1; otherwise, it is 0. Therefore, the sorted ciphertext can be uniformly represented as:

[0106]

[0107] It ensures that for each target location Only one condition is met. of Once selected, the sorting is correctly achieved. The K-nearest neighbor selection process is completed in the ciphertext field or with client assistance, without the need to decrypt the distance value.

[0108] The following specific examples further illustrate the implementation process of S4:

[0109] Assuming K=3, there exist 4 fully homomorphic encryption algorithms whose Euclidean distances, X' = {, need to be sorted. , , …, } = {3.2,1.5,4.7,2.8}, corresponding to the original data labels { It is particularly important to note that the Euclidean distance corresponding to each encrypted training sample shares the label of that sample; that is, the label of the Euclidean distance corresponds to the label of the corresponding encrypted training sample.

[0110] Through S41, the position value sequence under fully homomorphic encryption can be obtained as A = { … The specific calculation process includes:

[0111] 1) Calculation :

[0112]

[0113] Substitute the encrypted data X' into the formula. The subtraction operations for array A are shown in Table 1 below:

[0114] Table 1

[0115]

[0116] As shown in Table 1, when the indices are 3, 4, and 2, the numerator is equal to 0. Therefore, only the result of 1 is retained. The denominator and numerator are both (1-2)(1-3)(1-4). Elimination yields 1, i.e. = 3.2 * 0 + 1.5 * 1 + 4.7 * 0 + 2.8 * 0 = 1.5, thus obtaining the minimum value of 1.5.

[0117] 2) Calculation :

[0118]

[0119] As shown in Table 1, when the indices are 3, 1, and 4, the numerator is 0. Therefore, only the result of 2 is retained. The denominator and numerator are both (2-1)(2-3)(2-4). Elimination yields 1. = 3.2 * 0 + 1.5 * 0 + 4.7 * 0 + 2.8 * 1 = 2.8, thus solving for the second smallest value in the ciphertext.

[0120] (3) Calculation :

[0121]

[0122] As shown in the table above, when the indices are 1, 2, and 4, the numerator is equal to 0. Therefore, only the result of 3 is retained. The denominator and numerator are both (3-1)(3-2)(3-4). Elimination yields 1, i.e. = 3.2 * 1 + 1.5 * 0 + 4.7 * 0 + 2.8 * 0 = 3.2, thus solving for the third digit of the ciphertext data;

[0123] Furthermore, the calculated sequence of ciphertext sample feature vectors = {E(1.5),E(2.8), E(3.2)}.

[0124] In implementation S5, each ciphertext distance in the ciphertext K-nearest neighbor distance set is subtracted from each ciphertext distance in the ciphertext distance set to generate difference information. This difference information is then packaged with the corresponding training sample's category label to generate a ciphertext package set. This includes:

[0125] Set the nearest neighbor distances of the ciphertext K. Distance of each ciphertext in The distance sets between each ciphertext and the ciphertext are respectively Distance of each ciphertext in Subtraction is performed in the encrypted state to generate the difference information. and each difference information Category labels of corresponding training samples Packaging, generating a ciphertext package collection .

[0126] In implementation S6, the encrypted package is returned to the client. After decryption, the client determines the final category of the sample to be classified based on the difference information; including:

[0127] Pack the ciphertext into a set Send back to the client;

[0128] The client uses the same private key as the encryption key for each difference in the set. Decrypt;

[0129] Calculate the category label corresponding to the zero difference among all decryption results, and take the category that appears most frequently as the final classification result for the sample to be classified. :

[0130]

[0131] in, This represents a set of category labels, where c represents one of the categories. This indicates an indicator function that returns 1 when a condition is met and 0 otherwise. This indicates the corresponding decryption function.

[0132] Specifically, the received ciphertext is packaged into a set. The results after decryption are shown in Table 2 below:

[0133] Table 2

[0134]

[0135] As shown in Table 2, the statistics are as follows: When the value is 0, we can see that there are 2 AA classes, 1 BB class, and 0 CC classes. Therefore, the test sample is finally classified as AA class.

[0136] The following sections describe the ciphertext K-nearest neighbor classification method based on fully homomorphic encryption in this embodiment from the perspectives of technical correctness, security assurance, and overall beneficial effects.

[0137] Based on correctness, the Euclidean distance was accurately calculated by sequentially performing homomorphic subtraction, multiplication, and summation of feature vectors in the ciphertext domain. The decryption result was completely consistent with the plaintext calculation. On this basis, the K minimum distance values ​​were selected and the corresponding samples were chosen in the fully ciphertext state using the ciphertext comparison function and the sorting mapping based on the Lagrange interpolation polynomial, ensuring the correctness of the K nearest neighbor selection. The final classification decision can also be completed in the ciphertext domain or after decryption, ensuring that the output results of the entire classification process are consistent with the traditional plaintext K nearest neighbor algorithm.

[0138] For security reasons, after the training samples and the samples to be classified are encrypted on the client side, all subsequent calculations are performed in the ciphertext state. The server cannot obtain any plaintext feature information. The encryption key is independently controlled by the client. The server can only operate on the ciphertext data and cannot perform decryption. The fully homomorphic encryption algorithm based on lattice or modulo components can resist common ciphertext analysis attacks, thus providing end-to-end privacy and security protection for the original data throughout the entire calculation process. This effectively meets the core security requirement of data being usable but not visible in data outsourcing scenarios.

[0139] This embodiment provides a complete method for K-nearest neighbor classification in a fully encrypted state, effectively solving the privacy leakage risk in data outsourcing computation. The correct classification result can be obtained without decryption on the server side. At the same time, the solution takes into account the scalability of computation, and supports vectorization and batch computation to adapt to the needs of large-scale data processing. It provides a safe, reliable and practical technical solution for intelligent analysis of privacy protection in sensitive data fields such as medical, financial and government affairs.

[0140] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the systems disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant parts can be referred to the method section.

[0141] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A ciphertext K-nearest neighbor classification method based on fully homomorphic encryption, characterized in that, Includes the following steps: S1. Obtain the training sample set of known categories, preprocess the feature vector of each sample and perform fully homomorphic encryption to generate the ciphertext training set; S2. The feature vectors of the samples to be classified are fully homomorphically encrypted on the client side to generate ciphertext test samples; S3. Calculate the Euclidean distance between the ciphertext test sample and each training sample in the ciphertext training set to obtain the ciphertext distance set; S4. Based on the ciphertext distance set, select the K ciphertext distances with the smallest distances using a ciphertext sorting algorithm to generate a set of K nearest neighbor ciphertext distances. include: S41, Based on Ciphertext Distance Set The ciphertext position value is calculated for each ciphertext distance using a ciphertext comparison function; S42. Using the ciphertext position values, and through a sorting mapping function based on the Lagrange interpolation polynomial, select the K nearest neighbor distances with the smallest ciphertext position values ​​to generate a set of K nearest neighbor distances for the ciphertext. ;include: Define the sequence of feature vectors of the encrypted training samples as { , ,…, The corresponding ciphertext position value sequence is { , ,…, } and the target location set T={1,2,…,N}; For each target sorting position k∈{1,2,…,K}, calculate the feature vector of the ciphertext sample sorted at the k-th position. : in, For indicator-type basis functions, the following condition is met: if and only if the ciphertext position value The corresponding plaintext position value is equal to hour, The corresponding plaintext result is 1, otherwise it is 0; Let T represent the set obtained by removing element k from set T, where t is the set to be traversed. A loop variable containing all elements; S5. Subtract each ciphertext distance in the ciphertext K nearest neighbor distance set from each ciphertext distance set to generate difference information, and package the difference information with the category label of the corresponding training sample to generate a ciphertext package set. S6. The encrypted package is returned to the client. After decryption, the client determines the final category of the sample to be classified based on the difference information.

2. The ciphertext K-nearest neighbor classification method based on fully homomorphic encryption according to claim 1, characterized in that, S1 includes: Obtain the training sample set , For the first The feature vector of each sample For the corresponding category label; For the feature vector of each training sample Preprocessing is performed, including normalization and missing value imputation; Each preprocessed feature vector is encrypted using a fully homomorphic encryption algorithm. Encryption is performed to obtain the ciphertext training vector. Constructing a ciphertext training set .

3. The ciphertext K-nearest neighbor classification method based on fully homomorphic encryption according to claim 1, characterized in that, S2 includes: Extract the feature vector x of the sample to be classified; The feature vector x is encrypted on the client side using a fully homomorphic encryption algorithm to obtain the ciphertext test sample. .

4. The ciphertext K-nearest neighbor classification method based on fully homomorphic encryption according to claim 1, characterized in that, S3 includes: For each ciphertext training vector in the ciphertext training set Calculate its relationship with the ciphertext test sample in the ciphertext state. Euclidean distance The ciphertext distance set is obtained. The Euclidean distance Represented as: in, Representing ciphertext training vectors The j-th component, Indicates encrypted test sample The j-th component.

5. The ciphertext K-nearest neighbor classification method based on fully homomorphic encryption according to claim 1, characterized in that, S41 includes: Define ciphertext comparison function Used to compare two ciphertext values and Size: in, Represents a symbolic function, and when hour, The corresponding plaintext result is 1, otherwise it is 1. ; For the ciphertext distance corresponding to the i-th training sample Calculate its ciphertext position value : in, , Let i and j represent the ciphertext distances corresponding to the i-th and j-th training samples, respectively. The plaintext value represents the position number of the ciphertext distance in ascending order.

6. The ciphertext K-nearest neighbor classification method based on fully homomorphic encryption according to claim 1, characterized in that, S5 includes: Set the nearest neighbor distances of the ciphertext K. Distance of each ciphertext in The distance sets between each ciphertext and the ciphertext are respectively Distance of each ciphertext in Subtraction is performed in the encrypted state to generate the difference information. and each difference information Category labels of corresponding training samples Packaging, generating a ciphertext package collection .

7. The ciphertext K-nearest neighbor classification method based on fully homomorphic encryption according to claim 6, characterized in that, S6 includes: Pack the ciphertext into a set Send back to the client; The client uses the same private key as the encryption key for each difference in the set. Decrypt; Calculate the category label corresponding to the zero difference among all decryption results, and take the category that appears most frequently as the final classification result for the sample to be classified. : in, This represents a set of category labels, where c represents one of the categories. This indicates an indicator function that returns 1 when a condition is met and 0 otherwise. This indicates the corresponding decryption function.

8. The ciphertext K-nearest neighbor classification method based on fully homomorphic encryption according to claim 1, characterized in that, The fully homomorphic encryption uses a lattice-based fully homomorphic encryption algorithm or a modular component-based fully homomorphic encryption algorithm, and supports homomorphic operations of addition and multiplication.