# Secure Control of Linear Controllers Using Fully Homomorphic Encryption
## 4 Control System with Encrypted Controller
### Encrypted Controller Using BFV Encryption Scheme  
First, we encrypt the controller using the BFV encryption method and follow the method in the literature [16] to adopt precomputation to save the time of encryption. We describe the process for this scheme based on Figure 4 in the following. We have drawn the flowchart as Figure 5 to help understand. Figure 4: The schematic diagram of a networked control system with BFV encryption. **Scheme 1:**  
We describe each step in detail based on the above flowchart:  
* The parameters \(\mathbf{A,B,C}\), and \(\mathbf{D}\) as well as the controller's initial state \(\mathbf{x(0)}\), are encrypted to produce its ciphertext \(\mathbf{\hat{A},\hat{B},\hat{C},\hat{D},\hat{x}(0)}\) in the controller's design, and this ciphertext is transmitted to the controller. * The sensor collects the signal \(\mathbf{y}\) and then uses the plaintext index to look up the table generated by precomputation to obtain the corresponding ciphertext \(\mathbf{\hat{y}}=\mathbf{Enc}(\mathbf{y})\), thus realizing the encryption process, which is then passed to the encrypted controller. * The encryption controller performs homomorphic operations after obtaining the ciphertext signal \(\mathbf{\hat{y}}\). The BFV homomorphism operation states that (1) really operates in the cipher space after being encrypted as: \[ \begin{split}\mathbf{\hat{x}}(t+1)&=\mathbf{\hat{A}} \times\mathbf{\hat{x}}(t)+\mathbf{\hat{B}}\times\mathbf{\hat{y}}(t)\\ \mathbf{\hat{u}}(t)&=\mathbf{\hat{C}}\times\mathbf{\hat{x}}(t)+ \mathbf{\hat{D}}\times\mathbf{\hat{x}}(t)\end{split} \] (4) The ciphertext \(\mathbf{\hat{x}}(t+1)\) of the state and the ciphertext \(\mathbf{\hat{u}}(t)\) of the output are passed to the actuator after the homomorphic operation is completed. * The actuator block decrypts the controller's output cipher to obtain \(\mathbf{u}(t)\) and applies it to the plant, decrypts the \(\mathbf{\hat{x}}(t+1)\) to obtain the state \(\mathbf{x}(t+1)\) and passes it to the sensor. * The state \(\mathbf{x}(t+1)\) is encrypted by the sensor and sent to the encrypted controller. **Remark 1**. : _(About the table generated by the precomputation)_  
1. _Based on the plant, the control function, and the initial condition, we can identify the range of_ \(\mathbf{x}\) _and_ \(\mathbf{y}\)_._
2. _We run the control system, create plaintext-ciphertext pairs_ \((m,h)\) _by encryption, and place them in a table. The final generated table contains all pairs between_ \(\mathbf{y}\) _and_ \(\mathbf{x}\)_._
3. _The table can determine the corresponding ciphertext when the sensor gathers the value_ \(\mathbf{y}\) _of the plant and encrypts it._  
Figure 5: The flowchart of a networked control system with BFV encryption. **Remark 2**. : _(About state \(\mathbf{x}(t)\)) To avoid the problem that the noise of the ciphertext \(\mathbf{x}(t)\) increases significantly after homomorphic addition and homomorphic multiplication in the encrypted controller, the following measures are taken. The ciphertext of state \(\mathbf{x}(t+1)\) after homomorphic encryption is sent to the actuator for decryption and then returned to the cryptographic controller for a new round of homomorphic computation after sensor encryption._  
With regard to Figure 5, we explain the illustration in detail by means of the following example. We want to control a conveyor belt to move a table through the control system. Then, at the beginning, we need to initialize the settings. The transmission speed has an upper limit, so we generate a plaintext-ciphertext table for the range of the speed. After successful initialization, we can start the subsequent operation. Suppose we input speed \(v\); the axis begins to rotate and moves the table. At this point, the following workflow begins. The sensor obtains the axis rotation speed \(v_{1}\), consults the table to generate the ciphertext value \(c_{v_{1}}\), and sends it to the encrypted controller. The encrypted controller carries out operations in the form of ciphertext to generate new states and signals.