# Trusted Energy-Aware Hierarchical Routing (TEAHR) for Wireless Sensor Networks
## 3 Proposed Studies
### Proposed Algorithm  
As per the definition of Trust, it is not easy to create Trust in the dynamic nature of wireless sensor networks. In our proposed study, we tried to create Trust between sensor-to-sensor nodes and sensor nodes to cluster heads, as well as between the cluster heads. So, on the basis of this Trust, we measure the anomaly in the wireless sensor network, and we propose a framework for that. In the proposed algorithm, it is designed to evaluate the trustworthiness of nodes within a WSN. The variables used in this algorithm are presented next. xi: Represents an individual standard (non-cluster head) Node within the network. CH: Represents a cluster-head node. Cluster heads are specific nodes that take on additional responsibilities, such as coordinating communication within their cluster. CH.T: This is the Trust Table associated with a Cluster Head. It stores trust-related information about the normal nodes in that cluster. On the basis of these variables, the Trust is calculated as follows: T_energy(x\({}_{i}\)): Energy Trust. Measures how much energy a node has remaining relative to its maximum capacity (E_res(x\({}_{i}\))/E_max). Nodes running low on energy might be more susceptible to compromise. T_forward(x\({}_{i}\)): Forwarding Trust. Calculates how reliably a node forwards data packets as intended (P_forwarded(x\({}_{i}\))/P_received(x\({}_{i}\))). T_consistency(x\({}_{i}\)): Consistency Trust. Ensures that nodes are forwarding data packets consistently (P_consistent(x\({}_{i}\))/P_forwarded(x\({}_{i}\))). Inconsistent behavior could indicate problems. T_behavior(x\({}_{i}\)): Behavior Trust. A more complex measure is based on whether the Node follows the network rules and its past activity. So, overall, Trust and Threshold T_overall(x\({}_{i}\)): Combined trust score for the Node, calculated using a weighted sum of individual trust factors (with weights w1, w2, w3, and w4). T_threshold: Dynamically adjusted Threshold based on the network's current state and past data. This allows the algorithm to adapt to changing conditions. The algorithm of the proposed study is as follows. In Algorithm 1 the lines 1-2 Initialization of cluster_head_selection, which takes the network N and cluster head CH. Loop through each node x\({}_{i}\) in the cluster of CH. Lines 3-9 If x\({}_{i}\) is in the CH.T trust table, calculate the trust metrics, i.e., Energy Trust, Forwarding Trust, Consistency Trust, and Behavior Trust. Then, compute the overall trust score T_overall(x\({}_{i}\))T_overall(x\({}_{i}\))T_overall(x\({}_{i}\)) based on the weighted sum of the individual trust metrics. Then, a dynamic trust threshold T will be set based on network conditions and historical data. Lines 10-21 will perform the decision to find the Trust if the overall trust score T_overall(x\({}_{i}\)) is below the Threshold: If x\({}_{i}\) shows signs of malicious behavior, then broadcast an alert about x\({}_{i}\) and block x\({}_{i}\) from all network activities. Otherwise, Flag x\({}_{i}\) for re-evaluation to limit its network participation and update the trust level of x\({}_{i}\) in the trust table CH.T. If the overall trust score T_overall(x\({}_{i}\)) is above the Threshold, then confirm x\({}_{i}\) participation in network activities and update the trust level of x\({}_{i}\) in the trust table CH.T. Line 22 End the loop for each Node in the cluster. In Algorithm 2 the lines 1-5 Define the function setup_dynamic_trust_thresholds, which takes the network N and cluster head CH. For each node xi in the cluster of CH, calculate the initial trust threshold T_threshold and continuously update it. Lines 6-17 evaluate the Trust for all nodes, the same as in previous algorithm with additional adjusted routes dynamically based on the latest trust assessments. If the overall trust score T_overall(x\({}_{i}\)) is below the threshold T_threshold, redirect critical communications away from x\({}_{i}\).