# Multibyte Electromagnetic Analysis Based on Particle Swarm Optimization Algorithm
## 4 PSO-Correlation Electromagnetic Analysis (PSO-CEMA)  
In this section, we will describe our approach toward multiple bytes of the key and optimization algorithm in detail. PSO-CEMA transforms the problem of the right key searching into the problem of optimizing correlation coefficients of key candidates. Each byte of the key is considered as a dimension, so each point in the coordinate is a key candidate. Recovering the right key means finding the best point in the multidimensional coordinate. In order to take full advantage of useful information, all \(m\) bytes of the key are used. Hamming distance \(AW\) from the current state \(H=(h_{1},h_{2},\cdots,h_{m})\) to the next state \(S=(s_{1},s_{2},\cdots,s_{m})\) is given as  
\[AW=HD(H,S)=\sum_{j=1}^{m}HW(h_{j}\oplus s_{j})=\sum_{j=1}^{m}HW(h_{j}\oplus f (h_{j},x_{j})) \tag{8}\]  
PSO is a heuristic and extremely simple algorithm that seems to be effective for optimizing a wide range of target functions or fitness functions. Its target is to find the best key point solution from the search space. The PSO algorithm can be summarized as follows:  
Given the target function \(F(x)\):  
\[\rho_{TAW}=\frac{N\sum_{i=1}^{N}T_{i}AW_{i}-\sum_{i=1}^{N}T_{i}\sum_{i=1}^{N} AW_{i}}{\sqrt{N\sum_{i=1}^{N}T_{i}-(\sum_{i=1}^{N}T_{i})^{2}\sqrt{N\sum_{i=1}^{N} AW_{i}-(\sum_{i=1}^{N}AW_{i})^{2}}}} \tag{9}\]  
Find \(F(x_{best})\geq F(x)\) \((\forall x\in\Omega^{D})\)  
where \(F(x)\) is the PSO's fitness function or target function, \(AW=[AW_{1},AW_{2},\cdots,AW_{N}]\), \(AW_{i}\) is the \(i\)th intermediate output's Hamming distance. The \(D\)-dimensional domain \(\Omega^{D}\) is the particle swarm search space which indicates that there are \(D\) bytes in a key, \(K=[k_{1},k_{2},\cdots,k_{D}]\). The key is transformed into multidimensional form, \(X=K\). Each byte of the key is considered as a dimension  
\[ \begin{cases}x_{1}=k_{1}\\ x_{2}=k_{2}\\ \vdots\\ x_{D}=k_{D}\end{cases} \]  
Thus, every key candidate solution is defined as a particle. The \(i\)th key candidate particle is represented as \(X_{i}=(x_{i1},x_{i2},\cdots,x_{iD})\). The movement of \(X_{i}\) follows Equation (3). The velocity for particle \(i\) is represented as \(V_{i}=(v_{i1},v_{i2},\cdots,v_{iD})\) and the velocity of the key candidate particle is updated in a new way according to the following equation:  
\[v_{id}=\omega v_{id}+c_{1}r_{1}(\mathit{pbest}_{id}-x_{id})+c_{2}r_{2}( \mathit{gbest}_{gd}-x_{id}) \tag{10}\]  
where \(\omega\) is the inertia weight and its value is non-negative. Inertia weight \(\omega\) plays an important role of balancing the performance of global optimization and local optimization. When \(\omega\) is large, the performance of global optimization ability is good, but the performance of local search optimization ability is poor. Considering stronger search ability, inertia weight \(\omega\) is modified to have a better convergence speed. The expression of the modified inertia weight is described as follows:  
\[\omega=\omega_{max}-(\omega_{max}-\omega_{min})\frac{iter}{max_{iter}} \tag{11}\]  
where \(\omega_{max}\) and \(\omega_{min}\) are the maximum inertia weight and the minimum inertia weight, \(iter\) is the current iteration number, and \(max_{iter}\) is the maximum number of iteration. In order to search the optimal key candidates, the particles move towards the best key point in the search space. In addition, in order to have a global optimal value, we add a mutation operator to the PSO algorithm. The mutation operator is used to maintain diversity from one iteration of a population to the next. It is analogous to biological mutation. The mutation operator alters one or more position values in the multidimensional coordinate from its initial state. In mutation, the solution may change entirely from the previous solution. Hence, it will come to a better solution by using the mutation operator. The mutation operation will change some particle positions with a mutation probability \(P_{m}\) to avoid local optimum.