## 3 CSCL-WVE-UDI: Method for Identifying Unknown IoT Devices
### Algorithm for Generating Permutation Positive-Negative Sample Pairs (PNSPs)
#### 3.3.3 PNSP Algorithm  
Based on the process above, we propose an algorithm to generate PNSP. The pseudocode for the PNSP algorithm is presented in Algorithm 3. ```
1:\(S\leftarrow(s_{1},\ldots,s_{i},\ldots,s_{f})\) // Sample Load Data for IoT Devices
2:\(Po\leftarrow(po_{1},\ldots,po_{1},\ldots,po_{f})\); \(Ne\leftarrow(ne_{1},\ldots,ne_{i},\ldots,ne_{f})\) // Full permutation of positive and negative pairs of samples
3:\(G\leftarrow[]\); \(Po\leftarrow[]\); \(Ne\leftarrow[]\)
4:for each \(s_{i}\) in \(S\)do // Traverse the payload samples of the i-th category of IoT devices
5:for each \(s_{i}^{j}\) in \(s_{i}\)do // Traverse the j-th payload sample
6:\(h_{s_{i}^{j}}\leftarrow\text{Improved-Nilsimsa}(s_{i}^{j})\) // Call Algorithm 2 to generate a 512-bit hexadecimal hash value
7:\(g_{i}^{j}\gets h_{s_{i}^{j}}\) use Pillow // Generating grayscale images with the Pillow library
8:endfor
9:\(G\gets g_{i}\) // Store the grayscale images of the i-th category of IoT devices
10:endfor
11:for each \(i\gets 1\) to \(f\)do
12:\(po_{i}\leftarrow\text{combine all positive pairs for }g_{i}\)
13:\(Po\gets po_{i}\) // Current IoT devices without duplicate positive pair samples
14:for\(ii\gets i+1\) to \(f\)do // Filtering already generated negative pair samples
15:for\(k\gets 1\) to \(len(g_{i})\)do
16:for\(p\gets 1\) to \(len(g_{i})\)do
17:\(ne_{i}\leftarrow(g_{i}^{k}\cdot g_{ii}^{p})\)
18:endfor
19:endfor
20:\(Ne\gets ne_{i}\) // Sample of all negative pairs of current IoT devices
21:endfor
22:endfor
23:return \(Po\); \(Ne\)
```  
**Algorithm 3** PNSP Algorithm  
The computational overhead of Algorithm 3 primarily originates from traversing the IoT device payload samples to generate hash values, as well as from generating permutation sample pairs. Generating the 512-bit hexadecimal hash value requires traversing every payload sample of each IoT device, with a time complexity of \(O\big{(}n^{2}\big{)}\). The permutation sample-pair generation requires matching positive and negative sample pairs and filtering out previously matched negative sample pairs, thus resulting in a time complexity of \(O\big{(}n^{4}\big{)}\). Thus the total time complexity of Algorithm 1 mainly results from the permutation sample-pair generation. Figure 4: Flowchart for generating a set of permutation positive–negative sample pairs. Embedding-Vector Database Generation Based on CSCL-Siamese Network: Embedding-Vector Database Construction (EVDC)-CSCL-Siamese Algorithm  
Embedding vectors offer an efficient feature-representation method that accurately captures the core characteristics and structural information of device fingerprints [5]. The network model, as a key technology for generating embedding vectors, is used primarily to deeply learn and extract complex features of device fingerprints and then map them into a high-dimensional embedding-vector space for an effective representation of the fingerprints. This representation approach preserves key features of device fingerprints while facilitating the numerical expression of the fingerprints, thereby providing robust support for subsequent similarity calculations among various IoT devices. Existing models, such as recurrent neural networks and GANs, can generate embedding vectors suitable for multiclass identification after extensive training, thus enabling the effective identification of multiple types of known IoT devices. However, these models necessitate frequent retraining to adapt to the continually increasing number of unknown IoT devices, which renders it difficult to satisfy the requirement of identifying increasing numbers of IoT devices in open environments. Hence, we propose an embedding-vector database-generation model based on the CSCL-Siamese network. This model employs a Siamese network trained using a cost-sensitive loss function to identify known IoT devices. Additionally, it leverages traffic data from known IoT devices to construct an embedded vector database, thus facilitating similarity computations with embedding vectors from unknown IoT devices.