# Privacy Preserving Classification of EEG Data Using Machine Learning and Homomorphic Encryption
## 2 Methods  
### Encoding Scheme  
Although integrating homomorphic encryption schemes with encoding methods addresses some of the impediments that hinder their real-world utility, there are still difficulties to be considered for obtaining an efficient encoding technique. As HE schemesare already complex, and encrypted operations require a higher computational cost than their plaintext equivalent, adding a new layer of encoding increases the complexity even more. Furthermore, expressing a value as a sequence of numbers leads to a ciphertext of growing size, as every number from the sequence is translated to its encrypted form. For example, when considering a polynomial representation, the multiplication of two encoded values results in an increased number of terms and polynomials with a higher order. As the number of operations increases, the increasing dimension is more difficult to handle, and performing computations becomes more time-consuming. As discussed in the introduction, encoding based on a polynomial representation is a common technique used to allow for real number encryption. Our approach is to use a polynomial representation of a number, based on negative powers of 10. Since the focus lies on enabling the encryption of real numbers, we deal with the integer and the rational part separately. Let us consider \(A\in R\), a real number represented as \(A=a_{0},a_{1}a_{2}\ldots a_{n}\). All digits of the integer part, denoted by \(a_{0}\), are encoded in the first coefficient of the polynomial, corresponding to 10 to the power of 0. The rational part is handled differently, by multiplying each digit with a negative power of 10, according to their position in the initial number. Adding these partial products, as in Equation (1), we obtain the encoding of a real value that consists of a sequence of small integers. \[A=a_{0}10^{0}+a_{1}10^{-1}+a_{2}10^{-2}+\ldots+a_{n}10^{-n} \tag{1}\]  
The \(n\) value denotes the number of decimals that are taken into account in this encoded representation and can be set, depending on the required precision for a certain application. To allow for the encryption of negative numbers, our proposed approach consists of replacing each coefficient of the polynomial with a difference, as in Equation (2). \[A=(a_{0}-b_{0})10^{0}+(a_{1}-b_{1})10^{-1}+(a_{2}-b_{2})10^{-2}+\ldots+(a_{n}- b_{n})10^{-n} \tag{2}\]  
If \(A\) is a negative number, then terms denoted by \(a_{0},a_{1},\ldots,a_{n}\) are equal to zero and the underlying information is stored in the \(b_{0},b_{1},\ldots,b_{n}\) terms, while preserving the sign of the number. From this point onward, referring to a polynomial coefficient designates a difference, such as \((a_{i}-b_{i})\). For instance, let us consider \(A=-13.8701\), which can be encoded as follows:  
\[-13.8701=(0-13)10^{0}+(0-8)10^{-1}+(0-7)10^{-2}+(0-1)10^{-4} \tag{3}\]  
We notice in this example that null decimals are ignored, simplifying the representation and allowing for an increase in precision. If, for a certain application, we have \(n=5\), the encoding takes into account only non-zero decimals, storing in the encoded representation more information from the original number. Using this method, it is possible to encode both positive and negative real numbers, with as many decimals as required, and then encrypt each coefficient by applying an HE scheme. The operations that can be performed on numbers encoded as previously explained are addition, subtraction and multiplication. As shown next, homomorphic properties with respect to these operations are preserved by this encoding technique since they are based on polynomial calculus. We consider two real numbers \(A_{1}\) and \(A_{2}\), with their corresponding generic encoded representations as follows:  
\[ \begin{split} A_{1}&=(a_{0}-b_{0})10^{0}+(a_{1}-b_{ 1})10^{-1}+\ldots+(a_{n}-b_{n})10^{-n}\\ A_{2}&=(c_{0}-d_{0})10^{0}+(c_{1}-d_{1})10^{-1}+ \ldots+(c_{n}-d_{n})10^{-n}\end{split}