### k-Means Clustering Phase  
The k-means clustering phase involves exploring the centroids of the entire dataset using the initial centroids calculated in the preprocessing phase. The execution steps of this phase are described in Algorithm 4. 1. Calculate the distances between E(data) and E(initial_center) using the SSED\({}_{\text{op}}\) protocol and determine the smallest distance (i.e., E(dist_min)) through the proposed ASMIN\({}_{\text{n}}\) protocol (lines 1-4). 2. C\({}_{\text{A}}\) calculates the difference between E(dist_min) and each encrypted distance, performs random insertion and permutation, and transmits the result to C\({}_{\text{B}}\) (lines 5-9). 3. C\({}_{\text{B}}\) decrypts each element of the received E(\(\beta\)), sets E(U\({}_{\text{j}}\)) = E(1) if \(\beta\) = 0, and sets E(U\({}_{\text{j}}\)) = E(0) otherwise. C\({}_{\text{B}}\) then sends E(U) to C\({}_{\text{A}}\) (lines 10-13). 4. C\({}_{\text{A}}\) reverses E(U) and stores it in E(V) (line 14). 5. Perform the SM protocol for E(V\({}_{\text{j}}\)) and E(data\({}_{\text{ij}}\)), summing the results for each dimension, and add the data with a distance of E(dist_min) to the new centroid E(new_center) (lines 15-19). Use the SETC protocol to calculate the termination condition (i.e., \(\alpha\)) between the initial and new centroids. Then, store new_center in initial_center, and if \(\alpha\) is 1, return initial_center to the user; otherwise, repeat the clustering algorithm from line 1 (lines 20-36). Figure 6 shows the example of the k-means clustering phase (k = 2). Firstly, C\({}_{\text{A}}\) calculates the distance between the initial centroids E([c]) and E([sample]) using the SSED protocol. In Figure 6, the distances between d\({}_{1}\) and the two centroids are computed as E(dist\({}_{1,1}\)) = SSED(E(d\({}_{1}\)),E(c\({}_{1}\))) = E(4), and E(dist\({}_{1,2}\)) = SSED(E(d\({}_{1}\)),E(c\({}_{2}\))) = E(50). Applying the SSED protocol to all 16 data points yields E([dist]) = [[E(4),E(50)], [E(0),E(40)], [E(2),E(34)], [E(4),E(20)], [E(36),E(4)], [E(40),E(16)], [E(50),E(10)], [E(64),E(8)], [E(4),E(36)], [E(16),E(40)], [E(10),E(26)]  
```
Input: E(data), E(node), E(threshold), E(initial_center) Output: cluster_center C\({}_{\rm A}\):
01. for 1 \(\leq\) i \(\leq\) n
02. for 1 \(\leq\) j \(\leq\) k
03. E(dist\({}_{\rm J}\)) = SSED\({}_{\rm OP}\)(E(data\({}_{\rm J}\)), E(initial_center))
04. E(dist_min) \(\leftarrow\) ASMIN\({}_{\rm n}\)(E(dist\({}_{\rm J}\)), \(\ldots\), E(dist\({}_{\rm J}\)))
05. for 1 \(\leq\) i \(\leq\) k
06. E(\(\rm{S}_{\rm i}\)) \(\leftarrow\) E(dist_min) \(\times\) E(dist\({}_{\rm J}\))N \(-\) 1
07. E(\(\rm{S}^{\prime}_{\rm i}\)) \(\leftarrow\) E(\(\rm{S}_{\rm i}\))r\({}_{\rm i}\)
08. E(\(\rm{\beta}\)) \(\leftarrow\)\(\pi\)(E(\(\rm{\beta}^{\prime}\)))
09. send E(\(\rm{\beta}\)) to C\({}_{\rm B}\):
10. for 1 \(\leq\) i \(\leq\) cnt
11. if D(E(\(\rm{\beta}_{\rm i}\)) = 0 then E(U\({}_{\rm i}\)) \(\leftarrow\) E(1)
12. else E(U\({}_{\rm i}\)) \(\leftarrow\) E(0)
13. send E(U) to CA
14. E(V) \(\leftarrow\)\(\pi-1\)(E(U))
15. for 1 \(\leq\) j \(\leq\) k
16. for 1 \(\leq\) l \(\leq\) m
17. E(V\({}^{\prime}\),j)\(\leftarrow\)SM(E(V), E(data\({}_{\rm i,J}\)))
18. E(new_center\({}_{\rm J}\),sum\({}_{\rm l}\)) \(\leftarrow\) E(new_center\({}_{\rm J}\),sum\({}_{\rm l}\)) \(\times\) E(V\({}^{\prime}\),j)
19. E(new_center\({}_{\rm J}\),cnt) \(\leftarrow\) E(new_center\({}_{\rm J}\),cnt) \(\times\) E(V\({}^{\prime}\))
20. \(\alpha\) = SECTC(E(initial_center), E(new_center), E(threshold))
21. if \(\alpha\) = 1
22. for 1 \(\leq\) i \(\leq\) k
23. for 1 \(\leq\) j \(\leq\) m
24. E(new_center\({}_{\rm J}\),sum\({}_{\rm l}\)+\(\tau\))\(\leftarrow\)E(new_center\({}_{\rm J}\),sum\({}_{\rm l}\)) \(\times\) E(r)
25. E(new_center\({}_{\rm J}\),cnt+\(\tau\))\(\leftarrow\)E(new_center\({}_{\rm J}\),cnt) \(\times\) E(r)
26. else
27. E(initial_center)+\(\leftarrow\)E(new_center)
28. go to line 1 in Algorithm 4
29. send r to AU and send E(new_center + r) to C\({}_{\rm B}\)
30.