# Trusted Energy-Aware Hierarchical Routing (TEAHR) for Wireless Sensor Networks
## 3 Proposed Studies
### Proposed Algorithm
2:Output: Dynamic threshold value
3:function setup_dynamic_trust_thresholds(N, CH)
4:for each x\({}_{i}\) in CH's cluster do
5:T_threshold \(\leftarrow\) calculate_initial_threshold(x\({}_{i}\))
6:continuously_update_threshold(T_threshold)
7:end for
8:for each x\({}_{i}\) in N do
9:if x\({}_{i}\) in CH.T then
10:T_energy(x\({}_{i}\)) \(\Leftarrow\) E_res(x\({}_{i}\))/E_max
11:T_forward(x\({}_{i}\)) \(\Leftarrow\) P_forward(x\({}_{i}\))/P_received(x\({}_{i}\))
12:T_consistency(x\({}_{i}\)) P_consistent(x\({}_{i}\))/P_forward(x\({}_{i}\))
13:T_behavior(x\({}_{i}\)) \(\Leftarrow\) evaluate_behavior(x\({}_{i}\))
14:T_overall(x\({}_{i}\)) \(\Leftarrow\) w1*T_energy(x\({}_{i}\)) + w2*T_forward(x\({}_{i}\)) +
15:w3*T_consistency(x\({}_{i}\)) + w4*T_behavior(x\({}_{i}\))
16:adjust_routes_based_on_trust(T_overall(x\({}_{i}\)), T_threshold)
17:ifT_overall(x\({}_{i}\)) < T_threshold then
18:redirect_critical_communications(xi)
19:endif
20:end if
21:end for
22:for each new_node in N do
23:if new_node meets_or_exceeds T_threshold then
24:integrate_node(new_node)
25:else
26:if probation_needed(new_node) then
27:extend_probation(new_node)
28:else
29:remove_node(new_node)
30:endif
31:end if
32:end for
33:periodically_recalculate_thresholds()
34:for each significant_event in network_events do
35:recalculate_T_threshold()
36:set_thresholds_using_predictive_analytics()
37:end for
38:for each x\({}_{i}\) in N do
39:if T_overall(x\({}_{i}\)) < T_threshold and is_malicious(x\({}_{i}\)), then
40:isolate_and_remove(x\({}_{i}\))
41:broadcast_alerts(x\({}_{i}\))
42:quarantine_node(x\({}_{i}\))
43:end if
44:update_CH_T()
45:end for
46:end function ```
**Algorithm 3**Setup Dynamic Trust Thresholds
```
1:N--Set of normal nodes, CH--Set of Cluster Heads, BS--Base Station
2:Efficient and secure routing of data based on Trust
3:function initialize_network(N, CH, and BS)
4:Deploy N sensor nodes randomly in the network area
5:Divide N into M clusters using a clustering algorithm
6:Select initial CHs using cluster_head_selection(N and CH)
7:Initialize trust levels for all nodes in N and CHs in CH
8:Set up initial routing tables for each Node and CH
9:end function
10:function trust_based_routing_setup(N, CH, and BS)
11:for each node xi in N do
12:Identify the closest Cluster Head CHi based on minimum energy cost
13:if T_overall(xi) \(\geq\) T_threshold then
14: Assign node xi to cluster CHi
15: Update routing table of xi to CHi
16:else
17:Flag xi for re-evaluation and assign to probationary CH
18:endif
19:end for
20:end function
21:function trust_based_data_transmission(N, CH, and BS)
22:for each Cluster Head CHi in CH do
23:Aggregate data from all nodes in CHi's cluster
24:Calculate Chi_Trust based on T_overall values of nodes in the cluster
25:if CHi_trust \(>\)= T_threshold then
26: Transmit aggregated data to BS using shortest path routing
27:else
28: Redirect data transmission to secondary or neighboring CH
29:Trigger cluster_head_selection(N and CH) for re-election of CH
30:endif
31:end for
32:end function
33:function dynamic_trust_management(N, CH, and BS)
34:for each node xi in N do
35:Recalculate T_overall(xi) using updated parameters
36:Adjust cluster membership based on T_overall(xi)
37:if T_overall(xi) < T_threshold then
38:Trigger re-evaluation or isolate xi based on severity
39:Update routing tables accordingly
40:endif
41:end for
42:Update dynamic trust thresholds using setup_dynamic_trust_thresholds(N and CH)
43:Adjust routes based on updated trust values and thresholds
44:end function

#### 3.2.1 Theoretical Analysis of TEAHR

Formal Proof of TEAHR's Robustness in Trust Evaluation

**Theorem 1**. : _TEAHR is Robust Against anomaly Sensor Nodes in Trust Estimation._

Proof. : by Strong Induction. Let T(x, y, \(\Delta\)t) denote the trust value assigned by sensor node x to sensor node y at time \(\Delta\)t.

Base Case: No Interaction Between Nodes x and y.