# A Secure Protocol against Selfish and Pollution Attacker Misbehavior in Clustered WSNs
## 4 Design and Implementation
### DoS and Pollution Attacks Prevention
#### 4.2.2 Decoding and Parts Reconstruction at \(B\)  
The decoding process is conducted by the \(BS\) for each source node. When the \(BS\) receives all the packets from \(CH\) nodes, it collects the packets belonging to the same source node \(N_{i}\) using its identity \(Id_{i}\).  
Since the adversary model guarantees that the \(BS\) receives at least \(t+1\) parts for each node, the \(BS\) is able to reconstruct the original data packet corresponding to each source node. In fact, the \(BS\) receives the parts \((m_{i,q_{1}},m_{i,q_{2}},\ldots,m_{i,q_{rp}})\) from different \(rp\) paths corresponding to different \(rp\)\(CH\)s, where \(t\leq rp\leq p\) (\(rp\) represents the number of received packets for a source node). In this case, it triggers the decoding process as follows:  
The \(BS\) checks for the \(p_{i}\) values received from the different packets, memorize the value \(p_{i}\) existing at least \(t+1\) times and distinguishes it as the true one (\(p_{i}^{T}\)) that has not been modified by an adversary. This is true because we assumed that the protocol guarantees that at least \(t+1\) packets are correctly received for each source node \(N_{i}\). Next, it checks the pre-loaded matrix \(A_{i}\) and extracts from it the sub-matrix \(A_{i}^{\prime}\) of size \(t\times p\) at  
Figure 4: The sub-matrix \(A_{i}^{\prime}\) extraction.  
the position value \(p_{i}^{\top}\). Afterwards, to reconstruct the original measurements, the \(BS\) uses each combination of \(t\) data parts out of the \(rp\) received parts to resolve the system of equations \(S_{1}(4)\). More specifically, it resolves a number value of \(C_{rp}^{t}\) systems to extract a set of possible original messages \(X_{i}^{(c)}=(x_{i,1}^{(c)},x_{i,2}^{(c)},\ldots,x_{i,t}^{(c)})\) as follows, where \(c\in\{1,\ldots,C_{rp}^{t}\}\) and \(C_{rp}^{t}=\frac{rp!}{t!\times(rp-t)!}\):  
\[\begin{cases}a_{q_{ij_{1}},x_{i,1}^{(c)}}+a_{q_{ij_{1}},2}x_{i,2}^{(c)}+\ldots +a_{q_{ij_{2}},t}x_{i,t}^{(c)}&=m_{i,q_{j_{1}}}^{(c)}\\ a_{q_{ij_{2}},x_{i,1}^{(c)}}+a_{q_{ij_{2}},2}x_{i,2}^{(c)}+\ldots+a_{q_{ij_{2}}, t}x_{i,t}^{(c)}&=m_{i,q_{j_{2}}}^{(c)}\\ \vdots&=\,\vdots\\ a_{q_{ij_{t}},x_{i,1}^{(c)}}+a_{q_{ij_{t}},2}x_{i,2}^{(c)}+\ldots+a_{q_{ij_{t}},t}x_{i,t}^{(c)}&=m_{i,q_{j_{t}}}^{(c)}\end{cases}\]  
where \(\{q_{ij_{t}},q_{j_{2}},\ldots,q_{j_{t}}\}\) are \(C_{rp}^{t}\) extracted combinations of size \(t\) from the set \(\{q_{1},q_{2},\ldots,\)\(q_{t},\ldots,\)\(q_{t},\ldots,q_{rp}\}\).  
Next, the \(BS\) detects the most apparent message in the set of the constructed messages \(X_{i}^{(c)}\) and recognizes it as the original one. The correct message will appear a number of times equal to \(C_{rp-pp}^{t}\) whereas each of the wrong messages will only appear once. \(pp\) depicts the number of polluted packets received at the \(BS\).  
The process of resolving the system of equations above can be done with a simple elimination of Gauss or by inverting the matrix made up of the different \(t\) encoding vectors of \(A_{i}^{\prime}\) to obtain a matrix of \(t\) columns \(q_{ij_{1}},\ldots,q_{j_{t}}\) corresponding to the different \(t\)\(CH\) nodes that sent the packets \(m_{i,q_{ij_{1}}},\ldots,m_{i,q_{j_{t}}}\) and which are stored in the routing table at the \(BS\). If the matrix \(A_{i}\) is chosen randomly and so is the matrix \(A_{i}^{\prime}\), there is no known method to rebuild the original data, even partially, from \((t-1)\) parts.