{'fraction_non_alphanumeric': 0.031157211291024983, 'fraction_numerical': 0.009501563799041926, 'mean_word_length': 4.281204265105583, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Security for Multi-hop Communication of Two-tier Wireless Networks with Different Trust Degrees

—Many effective strategies for enhancing network performance have been put forth for wireless communications’ physical-layer security. Up until now, wireless communications security and privacy have been optimized based on a set assump-tion on the reliability or network tiers of certain wireless nodes. Eavesdroppers, unreliable relays, and trustworthy cooperative nodes are just a few examples of the various sorts of nodes that are frequently categorized. When working or sharing information for one another, wireless nodes in various networks may not always have perfect trust in one another. Modern wireless networks’ security and privacy may be enhanced in large part by optimizing the network based on trust levels. To determine the path with the shortest total transmission time between the source and the destination while still ensuring that the private messages are not routed through the untrusted network tier, we put forth a novel approach. To examine the effects of the transmit SNR, node density, and the percentage of the illegitimate nodes on various network performance components, simulation results are provided.


I. INTRODUCTION
Although wireless communications have advanced significantly, particularly in the last two decades, they are now beginning to encounter significant security and privacy issues [1]- [4]. A lot of effective ways to boost network performance have been developed recently thanks to physical-layer security for wireless communications [5]. However, a number of parameters, including energy [6], channel estimation [7], [8], and trust factors [9]- [11], play crucial roles in maximizing security in real-world situations.
As of now, wireless communications security and privacy are maximized based on a predetermined belief in the dependability of the wireless nodes. According to [12]- [14], they are frequently divided into several sorts, such as eavesdroppers, untrusted relays, and trusted cooperative nodes [15]. However, a node's trustworthiness or TD may not always be obvious and is heavily influenced by the social connections between its users and those of legitimate nodes (such as friendship in social networks) [16]- [18]. As a result, TD concerns have to be taken into account while enhancing network efficiency to really provide improved security and privacy. More and more wireless, particularly small, gadgets are being utilized throughout the globe today for communication as well as for monitoring security, health, education, and the environment. Wireless nodes in various networks serving various functions and/or belonging to various organizations do not fully trust one another while relaying information for the other, yet they still need to work together because of distant or inaccessible locations. The solution to this issue is crucial for enhancing the security and privacy of the current wireless network, particularly when taking into account novel factors [9], [19], [20].
Physical-layer security studies have largely concentrated on one-hop or two-hop wireless networks. Several studies have recently looked into multi-hop scenarios. For instance, a multi-hop network with decode-and-forward (DF) relays is presented with a physical layer security-aware routing method. Analytically, a number of outage probabilities in near forms are obtained. However, not every route selection step in the routing algorithm takes the security limitations into account.
Only the final answer is used to calculate the security metrics using the well-known Bell-Ford technique [21]. Another study used the Bell-Ford method to determine the optimum path to the target [22], however unlike [21], it only takes into account fixed, obviously hostile nodes, commonly known as eavesdroppers. It is suggested to use a Dijkstra algorithm to randomize the routing in order to pick less predictable pathways. The model [23] concentrates on protocol features but ignores trust levels.
A few study groups have recently looked into the topic of two-tiered wireless networks [24]. However, to the best of our knowledge, this research is among the first to consider two tier networks with different trust degrees. This work's originality may be summed up as follows: • The route with the quickest total transmission time between the source and the destination that nonetheless ensures that the private messages are not routed through the untrusted network tier is what we suggest as our novel method. • We consider clustering with inter-cluster links through gateways and analyze their corresponding computational complexity. • We examine how transmit SNR, node density, and the percentage of the illegitimate nodes impact network performance indicators such the successful delivery rate, total transmission duration, and number of hops in a route.
The remainder of the paper is organized as follows. Section II presents the system model that the paper will follow. Section III describes the proposed routing algorithm. Section IV describes the simulation scenarios, presents and analyzes the results; and section V concludes the paper.

II. SYSTEM MODEL
We take into account a network of n nodes. To node n, node 1 wishes to deliver message s. Nodes 1 and n are legitimate nodes that are also referred to as the source and destination nodes, respectively. However, a trustworthy and reliable channel might not be what connects them directly. As a result, the other n − 2 illegitimate nodes will assist by decoding and sending the message hop by hop. The directly connecting and available link between node i and node j is denoted by l ij . If the distance between two nodes is larger than a threshold value of l T , there is not a reliable channel between them. We assume that each node has no buffer and must transmit all of the information it has received and decoded.
Since every node employs the DF relaying mode, a relaying node must be able to receive the signal from the previous node in the relaying route with sufficient SNR, fully decode the message, and then re-encode it at a rate equal to the channel capacity between it and the next node in the route. It implies that a relay will have full knowledge of s. We consider two trustworthy models as follows.
• Trust degree: When seen from the valid nodes, each node has a unique TD of t ∈ [0 1], i = 1, ..., n. It is the likelihood that a node does not exploit the data it obtains throughout the process of assisting with message decoding for nefarious purposes. Without a doubt, the TD of the legitimate nodes is always 1. The TDs of the relay set nodes that the message will pass through, indicated here by R, determine the security level of s. The probability that the message is utilized maliciously by at least one node is determined by p M = 1 − i∈R t i . We presume that s is not a fully protected communication, which means we tolerate the possibility that the message is used maliciously with a probability below a threshold level p T . If p T = 0, it requires that p M ≤ 0, so i∈R t i ≥ 1, i∈R t i = 1 or all relays have TDs of 1, the message is completely secured. • Network tiers: The wireless nodes belong to different network tiers, e.g., wireless sensors of different owners installed in a common area. We consider public and private messages. The nodes of the same network tier are completely trustful to each other so they can freely share and relay both public and private messages for each other. However, only public messages are shareable to nodes of the other network tier. Therefore, different from the trust degree that the malicious probability is multiplicatively accumulated along the route, a private is forbidden to go through any node in the other network tier. We also assume that only the next node in a route receives when a node in the route broadcasts. We only take into account the insecurity caused by the low trust degrees of the other network tiers' nodes and do not take into account the eavesdropping of specific eavesdroppers or other nontargeted illegitimate nodes. In case of a more general scenario where other nodes along the route can receive or overhear parts of the signal, the consequence is also the same as in the assumed scenario in this paper. A wireless network with accurate beamforming transmission between any two nodes and a wire network with copper or optical connections are two scenario examples with such a scenario.
Route R in the network has nodes renumbered from 1 (the source) to k (the destination, also node n in the network). The channel along the path between nodes i and i + 1 is designated as h i . The transmission's maximum achievable rate (MAR) from node i to node j is given by , i ∈ R where the transmit and noise powers, respectively, are denoted by p and σ2. The same constellation can be used if all nodes along the path transmit at the same rate, and the rate is given by r = min i,j∈R c i to guarantee that the message can be decoded by each receiver along the path. Each node along the route can re-encode the message with a new constellation, and as a result, a different rate of r i (bits/s/Hz), in order to improve the routing and boost end-to-end transmission rate. Assume that a 1-Hz bandwidth is used for all communications. It takes f ri seconds to send f bits from node i to node i + 1. When additional processing times are not taken into account, the amount of time it takes to send f bits over the selected route is provided by T = i∈R f ri (s). Since r i ≤ c i , to minimize T , r i should be chosen as c i and T = i∈R f ci (s).

III. PROPOSED ROUTING ALGORITHM
In a network, the shortest path between a source and a destination is found using the Dijkstra's method. Each possible link in the network has an additional cost, which is known in advance. The route from a source to a destination that incurs the least overall cost is called the shortest route. The method will progressively expand the known network to the target routing and move each node from the tentative list to the permanent list before checking every conceivable path [25].
The time it takes to transmit 1K bits from one node to the next is the cost in the Dijkstra's algorithm used in this study since we are looking for the path with the least delivery time. The cost of a connection is expressed as f ci . We denote the cost of link l ij by d ij . If d ij > c max , where c max is a very large number, node i and node j are not directly connected.

A. Clustering
For a large network with a huge number of nodes, it can be overloaded or impossible to put all links into a matrix. Moreover, some nodes are very far away from other nodes so there are no direct and reliable links between them. It is not necessary to consider all links in a common set. In addition, requiring the nodes to transmit to farther nodes will soon exhaust their energy. Due to all these reasons, separating the nodes into clusters has been considered for a long time.
For wireless sensor networks with data collection and aggregation purpose, a node in each cluster is selected as the cluster head. All nodes in a cluster report their sensed data to the cluster head which aggregates and forwards the aggregated value to the server of the cluster head of the upper-level cluster. However, this requires that the energy level of the cluster heads is high enough to transmit the signals to the far-away upperlevel cluster head or server.
There several methods for clustering. In this paper, we consider two basic clustering methods with a predetermined number of clusters, n C : grid-based clustering and K-means clustering as follows.
• Grid-based clustering: The network area is uniformly divided into n R rows and n C columns. There are n C = n Ro n Co rectangular clusters. The advantage of this clustering method is that the clusters are uniformly distributed so the inter-cluster links are not physically long. In fact, as assumed in the system model, there is no reliable channel between any two nodes whose distance is larger than l T . This means than grid-based clustering results in less isolated or separated clusters and increases the probability of successful data delivery from the source to the destination [26]. • K-means clustering: This method tries to optimally locate the centroids of n C clusters. First n C centroids are initially determined maybe randomly. Each node is associated to the cluster with the centroid closest to that node. The new centroid of each cluster is calculated based on all associated nodes of that cluster. The node association is re-determined and the centroids are re-calculated in an iterative way until the movements of the centroids are smaller than a threshold value [27]. We consider two basic clustering methods such as grid based clustering and k-means clustering because these methods are efficient in different scenarios and popularly used in many existing publications and have their own advantages. For gridbased clustering, we uniformly allocate equal area to all clusters so the inter-cluster head distances are not larger than a limit. For k-means clustering, the distance sum, for all cluster members to their heads, is minimized.
In a network without cluster heads, the data is routed inside a cluster from a data source to a gateway node. A gateway is an edge node of a cluster and directly connected to a gateway of the next cluster. There are probably several links connecting edge nodes of this cluster to edge nodes of an adjacent cluster. We can choose the best links which have the highest transmission capacities, to be inter-cluster links. The ends of those inter-cluster links become the corresponding gateways.
6) Check for improvement in the minimum cost path from node 1 to each node in Nj as follows 7) Go back to step (2) until S = ∅. There are two methods of choosing best links between a certain pair of clusters as follows.
• Non-repeated gateways: A node can be an end of more than one inter-cluster link. The gateways of the best intercluster link between clusters a and b is given by When the best link between clusters a and b is determined, it is removed out of the considered link set so that we can search for the second best link. In the k-th step, the best, the second best, ..., and (k−1)-th best links are removed of the considered link set and we search for the k-th best link. The gateways of this link is given by • Repeated gateways: A node can be an end of only one inter-cluster link. In step k, the link to be selected is given by where L k ab = L ab \ l l ab , l ∈ {1, ..., k − 1}, L ab is the set of all links between any node of cluster a and any node of cluster b. The gateways are selected correspondingly to link l k ab . The complexity of the Dijkstra algorithm for the unclustered network of n nodes can be represented by O(n 2 ). If the network is divided into n C clusters, we need to run the algorithm in each cluster with complexity O n nC 2 . We need to run for n C clusters so the complexity is O n 2 nC . With Algorithm 2: Finding the shortest path from node 1 to node n using grid-based inter-cluster routing through gateways such that all private messages do not go through any nodes of the second tier network. Data: Link costs dij, i, j ∈ {1, ..., n}; message type tM (0 = public, 1 = private); number of cluster nC; node position pi; number of gateway pairs between adjacent clusters nG.
Result: The gateway-to-gateway cost matrix G.
Steps: 1) Divide the nodes into grid of nG clusters based on positions pi. 2) If tM = 0, define black list B = ∅. Otherwise, B includes all nodes in the second tier network. 3) Find nG best links, with smallest costs, between any node of a cluster, except in the black list, and any node of an adjacent cluster, except in the black list: 4) Define gateway set G including the source (G(1)), destination (G(|G|)) nodes and all gateways. 5) Find the shortest path between every gateway, including the source (G(1)), of every cluster in G to any other gateway, including the destination (G(|G|)), of the same cluster in G using Algorithm 1 in Fig. 3. 6) Build the gateway-to-gateway cost matrix based on the cost of the shortest paths found in step 5. 7) Find the shortest path between the source and the destination through the gateway network based on the cost matrix achieved in step 6 using Algorithm 1 in Fig. 3. this complexity, we have the gateway-to-gateway cost matrix. If between any two adjacent clusters, there are two best n G links which are equivalent to n G gateway per cluster. If the network are clustered with √ n C rows and √ n C columns, there are 4 corners each with 2n G gateways; (4 √ n C − 4) clusters each with 3n G gateways; and (n C − 4 √ n C ) each with 4n G gateways. So the total equivalent complexity is given by 1 c ∼O n 2 n C + (4 × 2n G + (4 √ n C − 4)3n G (8) If n G is small enough, this is smaller than the complexity of the routing algorithm without clusters. Certainly, with a higher n G , the performance of the routing with clusters get closer to that of the routing with no clusters.

B. Trust degree
In order to take the trust degree into account, we alter the method by include the TD restriction in the suggested routing strategy. We therefore modify the algorithm by adding the constraint regarding the TDs in the proposed routing algorithm. In the network example in Fig. 1, six nodes with various TDs are displayed below the nodes in violet boxes. A related cost is displayed next to each link. The cumulative TD must exceed a predetermined TD threshold (α) in order for us to discover a path from node 1 to node 6 with the lowest accumulated cost. We identify the path in the network that has the lowest total cost between nodes i and j using the mathematical notation P ij its corresponding cost by D ij , and its corresponding accumulated TD by T ij . By denoting the set of all nodes along path P ij by R ij , we write T ij = m∈Rij t m . The routing algorithm is analogous to the following optimization problem for generic n. The optimization problem for the trust-degree routing is given by min P1n D 1n (11) subject to T 1n ≤ α.

IV. SIMULATION RESULTS
We give the simulation results and examine the many factors impacting the performance of the network in this part. In the simulations, the placements of n nodes are uniformly distributed randomly in a 1m×1m square. Only when the separation between two nodes is less than a threshold of d th = 0.4 can they establish a stable wireless connection. A reliable wireless channel has a σ 2 h -variance and 0-mean complex distribution that are dispersed at random. In a Normal , where c L is the light velocity, f R is the radio frequency, and d is the distance between the transmitter and receiver under consideration. One of the unlicensed frequency bands in the US is f R = 900 MHz, which we use. The channel's variation represents the Friis's Transmission Formula [28].
The nodes are divided into n C clusters using Grid-based clustering as shown in Fig. 5. The nodes of the first tier network, the legitimate nodes, are marked with color of its cluster while the nodes of the second-tier network in the same cluser are marked with darker colors. Intra-cluster links are shown with the same color of that cluster. Normal inter-cluster links are shown with dashed, thin, and black lines while the n G best links between any two adjacent clusters are shown with solid, think, and black lines. The data source and destination nodes are fixed at (0.1, 0.1) and (0.9, 0.9) in the first and last cluster, respectively, and shown with large circles.
After the best inter-cluster links are determined, their ends are defined as gateways. The data source and destination nodes are also (special) gateways. The Dijkstra routing algorithm is used to determine the shortest route, with the smallest total cost, from a gateway to any other gateways of the same cluster. The intra-cluster inter-gateway connections are now considered as a link with a cost obtained when running the routing algorithm above and shown as thin and blue lines in an example in Fig. 6. Note that the intra-cluster links are not directly physical link but the inter-cluster links are. Now the best route from the data source node to the data destination node is determined by Dijkstra routing algorithm with the gateway-to-gateway cost matrix obtained. As presented in Algorithm 2, when considering a node to be a gateway, the -9  1-6  2  1,2  1  1-2  1  1-3  2  1-2-5  9  1-6  3  1,2,3  1  1-2  1  1-3  2  1-2-5  6  1-3-6  4  1,2,3,5  1  1-2  1  1-3  2  1-2-5  4  1-2-5-6  5  1,2,3,5,6  1  1-2  1  1-3  2  1-2-5  4 1-2-5-6 Fig. 4. Steps of the proposed routing algorithm for the two-tier network in Fig. 1. Only nodes in the first-tier network are considered.  nodes in second tier network are excluded so the final routing algorithm used is pure Dijkstra's. If the number of intercluster gateways increases, the best route to be found is better, however, the complexity is higher both for finding the best inter-cluster links and finding the best route in the gatewayto-gateway network. The number of inter-cluster gateways connected between any two clusters does not necessarily the same.

A. Two-Tier Networks
The average delivery time for 1 Kbits from node 1 to node n is shown in Fig. 7. Since the receiver of each hop may receive a better signal and shorten the transmission time in each hop, it can be seen that all delivery times decrease with the transmit SNR of each hop. A no-cluster scheme will give a better routing solution as expected however it uses more signalling and computational resources due to higher complexity. A non-adaptive scheme always limits the considered nodes, for both selecting gateways in case of clustering and selecting intermediate nodes in intra-cluster routing, to the first tier network, known as legitimate nodes, only for both private and public data messages. An adaptive scheme considers nodes in the first tier network for a private message but all nodes in the network for a public message. Obviously, an adaptive scheme can find better routes in some cases. More nodes in a network result in a faster transmission rate or shorter transmission times between any two nodes since there is typically a shorter distance between them. In all simulation with two-tier networks below, we public and private messages account for half of the occurrences. Due to the complexity of a network with more than two tiers in which trustful relation between any two tiers are considered and quantified, it will be considered in a future work. Figure 8 shows the the affect of the percentage of illegitimate nodes on average delivery time for 1K bits in case n = 60, n G = 2, and d th = 0.3. Certainly, there are more and more nodes of the second tier network and less nodes of the first tier network, there are less options for the best route for a private message's routing. Therefore, the delivery time  increases correspondingly. Figure 9 shows the effect of the percentage of illegitimate nodes on the average number of hops that the best route take from the source to the destination. When the illegitimate nodes occupy more, it is more difficult to find the best intermediate legitimate nodes which satisfy the tier-appropriate constraint for a private message. So in this case it may accept a detour with more hops. Figure 10 shows the effect of the percentage of illegitimate nodes on on the successful delivery ratio. Not in all realizations of nodes' positions and channels, there is always a feasible route from the source to the destination. The source and the destination may be in two legitimately separated sub-networks. Therefore, when the illegitimate nodes occupy more, certainly the probability of a feasible route will decrease.

B. Trust Degree
A node's trust degree is randomly generated using a 1-mean and 0.4-variance. 2 If the random value is more than 1, the trust degree is set to 1; if it is lower than 0, the TD is set to 0. It is truncated in the value range of [0 1]. Fig. 11 shows the effect of the transmit SNR on the average delivery time. The curves have a similar shape with those of the two-tier networks. The trust degree can be seen as the case with the number of tiers is infinity and each tier network has a different trust degree seen from the legitimate network.

V. CONCLUSION
Modern wireless networks' security and privacy may be enhanced in large part by optimizing the network based on network tiers' trust levels. To determine the path with the shortest total transmission time between the source and the destination while still ensuring that the messages with a certain privacy level do not pass nodes of the network tiers with trust level smaller than a corresponding threshold value, we put forth a novel approach. To examine the effects of the transmit SNR, node density, and the probability of other network tiers' nodes on various network performance components, simulation results are provided. In order to improve routing optimization, boost security, and improve network speed, it is crucial to have a clustering scheme with enough number of gateways between adjacent clusters and appropriate complexity.