# Optimized Implementation and Analysis of CHAM in Quantum Computing
## 3 Quantum Implementation of CHAM
### Fse'20  
The second improvement method is the application of FSE'20 to the key-schedule. The method of applying PLU factorization uses CNOT and SWAP gates, while the method of applying FSE'20 uses only CNOT gates. The SWAP part uses a logical swap method that can include values to Python's list in the order you want them to. Since the process is too complicated to use the SWAP gate, a logical swap is used to intuitively know. Since  
Figure 3: Quantum circuit of the CHAM-64/128 key schedule with PLU factorization (Apply_L), white circle indicates XOR operation and black dot indicates connection. the logical swap method does not use quantum gates, the reverse operation is not applied immediately. Therefore, it is necessary to make an operation that performs the opposite process of the logical swap so that it can be put back in the original order in the list. The generation of round keys \(RK_{0\sim 7}\) with FSE'20 is described in Algorithm 3. If the reverse operation is performed in Algorithm 3, the reverse function can be applied to lines 1 to 14 in the same way as PLU factorization. Then, \(k\) has the original value if the same operation of line 16 to 19 is performed one more time. The reverse operation proceeds in the same way as the aforementioned PLU algorithm. ```
16-qubit Key \(k_{0\sim 7}\)
2:Round key\(RK_{0\sim 7}\)
3:Transform \(k_{0\sim 7}\):
4:for\(i=0\) to 7 do
5:\(k_{i}[5]\leftarrow\text{CNOT16}(k_{i}[13],\,k_{i}[5]),\quad k_{i}[2]\leftarrow \text{CNOT16}(k_{i}[10],\,k_{i}[2])\)
6:\(k_{i}[15]\leftarrow\text{CNOT16}([K7],\,k_{i}[15]),\quad k_{i}[8]\leftarrow \text{CNOT16}(k_{i}[0],\,k_{i}[8])\)
7:\(k_{i}[7]\leftarrow\text{CNOT16}(k_{i}[6],\,k_{i}[7]),\quad k_{i}[7]\leftarrow \text{CNOT16}(k_{i}[14],\,k_{i}[7])\)
8:\(k_{i}[4]\leftarrow\text{CNOT16}(k_{i}[12],\,k_{i}[4]),\quad k_{i}[14]\leftarrow \text{CNOT16}(k_{i}[5],\,k_{i}[14])\)
9:\(k_{i}[12]\leftarrow\text{CNOT16}(k_{i}[11],\,k_{i}[12]),\quad k_{i}[10] \leftarrow\text{CNOT16}(k_{i}[9],\,k_{i}[10])\)
10:\(k_{i}[13]\leftarrow\text{CNOT16}(k_{i}[4],\,k_{i}[13]),\quad k_{i}[0]\gets \text{CNOT16}(k_{i}[1],\,k_{i}[10])\)
11:\(k_{i}[12]\leftarrow\text{CNOT16}(k_{i}[3],\,k_{i}[12]),\quad k_{i}[9]\gets \text{CNOT16}(k_{i}[8],\,k_{i}[9])\)
12:\(k_{i}[1]\leftarrow\text{CNOT16}(k_{i}[8],\,k_{i}[1]),\quad k_{i}[0]\gets \text{CNOT16}(k_{i}[15],\,k_{i}[0])\)
13:\(k_{i}[8]\leftarrow\text{CNOT16}(k_{i}[0],\,k_{i}[8]),\quad k_{i}[3]\gets \text{CNOT16}(k_{i}[2],\,k_{i}[3])\)
14:\(k_{i}[6]\leftarrow\text{CNOT16}(k_{i}[5],\,k_{i}[6]),\quad k_{i}[4]\gets \text{CNOT16}(k_{i}[12],\,k_{i}[4])\)
15:\(k_{i}[11]\leftarrow\text{CNOT16}(k_{i}[2],\,k_{i}[11]),\quad k_{i}[15]\gets \text{CNOT16}(k_{i}[7],\,k_{i}[15])\)
16:\(k_{i}[2]\leftarrow\text{CNOT16}(k_{i}[10],\,k_{i}[2]),\quad k_{i}[5]\gets \text{CNOT16}(k_{i}[13],\,k_{i}[5])\)
```  
\(\triangleright\) logical swap
17:\(RK_{i}[0]\gets k_{i}[0]\)
18:for\(j=15\) to 1 step -1 do
19:\(RK_{i}[j-(\lceil j/2\rceil-1)*2]\gets k_{i}[j]\)
20:endfor
21:endfor
22:return\(RK_{0\sim 7}\) ```
\(\triangleright\) After performing encryption
```
16:Reverse (transform \(k_{0\sim 7}\))
23:return\(k_{0\sim 7}\) ```

**Algorithm 3** Quantum implementation of CHAM-64/128 Key Schedule applying FSE'20. ## 4 Performance

In this section, we evaluate and compare the performance of proposed CHAM quantum circuits by estimating the quantum resources. However, the proposed quantum circuits cannot yet run in current quantum computers because the size of our circuits are too large. We use ProjectQ, a quantum programming tool provided by IBM, on classical computers to implement and simulate quantum circuits. Thus, the quantum circuits in our work are implemented and simulated at an error-free environment (i.e., logical level). A large number of qubits can be simulated using ProjectQ's own library, ClassicalSimulator, which is limited to boolean quantum gates such as X, CNOT, and Toffoli. Quantum gates that affect the phase such as S and H gates cannot be used.