# Key-Recycling Strategies in Quantum-Key-Distribution Networks
## 5 QKR Mechanism and Strategy
### Mixed Recycling  
The mixed QKR algorithm is proposed to maximize the average security of the service without affecting the original high security level of the service. As shown in Algorithm 3, the joint parameters obtained by analyzing historical traffic characteristics and used for adaptive selective-key-recovery algorithms are \(\overline{R_{\text{sec}}}\), \(\overline{N_{key\_relay}}(R_{\text{sec}}=2)\), and \(\sigma_{N_{key\_relay}}(R_{\text{sec}}=2)\), respectively. x services before the current failed service are analyzed, where x is the number of historical data. \(\overline{R_{\text{sec}}}\) represents the weighted average security level of the service. a, b, c, and d are weighting coefficients. The closer the arrival time of the service is to the current time, the greater the weight.  
```
1:For each data service Ser (V\({}_{\text{s-d}}\), R\({}_{\text{sec}}\), t\({}_{\text{s-s}}\), t\({}_{\text{hd}}\)) do
2: Generate QKD (V\({}_{\text{s-d}}\), t\({}_{\text{s-d}}\), N\({}_{\text{key\_relay}}\), P\({}_{\text{failure}}\), T\({}_{\text{p}}\));
3: Storage N\({}_{\text{key\_relay}}\) and R\({}_{\text{sec}}\) of the service;
4:For each QKD service QKD (V\({}_{\text{s-d}}\), t\({}_{\text{s-q}}\), N\({}_{\text{key\_relay}}\), P\({}_{\text{failure}}\), T\({}_{\text{p}}\)) do
5: P\({}_{\text{set}}\)\(\leftarrow\)routing computation with D algorithm;
6:If flag bit shows relay failure && min \(\{\text{N}_{\text{key\_(i,p)}}\}<\overline{\text{N}_{\text{key\_lay}}(\text{ Rsec}=2)\) && \(\overline{R_{\text{sec}}}=\)2 then
7: Call Algorithm 1;
8:Else if flag bit shows relay failure && min \(\{\text{N}_{\text{key\_lay}}(\text{Rsec}=2)\) && \(\overline{R_{\text{sec}}}=\)3 then
9: Call Algorithm 2;
10:Else if flag bit shows relay failure && \(\sigma_{N_{key\_relay}}(R_{\text{sec}}=2)>=\text{th}_{\text{v}}\)then
11: Call Algorithm 2;
12:Else if flag bit shows relay failure && \(\sigma_{N_{key\_relay}}(R_{\text{sec}}=2)<\text{th}_{\text{v}}\)then
13: Call Algorithm 1;
14:End if
15:End for
```  
**Algorithm 3** Quantum Key Mixed Recycling  
Figure 8: QKR post processing algorithm.  
\[\begin{array}{rl}N(k)=&a\sum\limits_{i=0}^{x/4-1}Ser(i,R_{\text{sec}}=k)+b\sum \limits_{i=x/4}^{2x/4-1}Ser(i,R_{\text{sec}}=k)+\\ &c\sum\limits_{i=2x/4}^{3x/4-1}Ser(i,R_{\text{sec}}=k)+d\sum\limits_{i=3x/4}^{ x-1}Ser(i,R_{\text{sec}}=k)\\ \overline{R_{\text{sec}}}=\left\{\begin{array}{ll}2,&if\qquad N(k=2)>N(k=3) \\ 3,&\qquad\qquad\text{otherwise}\end{array}\right.\end{array} \tag{6}\]  
\(\overline{N_{key\_relay}}(R_{\text{sec}}=2)\) represents the average demand for keys for a service with a security level of two in the history.  
\[\overline{N_{key\_relay}}(R_{\text{sec}}=2)=\sum\limits_{i=0}^{x}N_{key\_relay }(i)/x \tag{7}\]  
\(\sigma_{N_{key\_relay}}(R_{\text{sec}}=2)\) represents the variance of the key demand for the service with security level two.  
\[\sigma_{N_{key\_relay}}(R_{\text{sec}}=2)=\sqrt{(\sum\limits_{i=0}^{x-1}{{{ \left(N_{key\_relay}(i)-\overline{N_{key\_relay}}\right)}^{2}}})/x} \tag{8}\]  
The interplay between Algorithm 1 and Algorithm 2 can be changed by adjusting the calculation method and weighting coefficient of related parameters. The essence of the algorithm is a compromise algorithm, which relies on the analysis of historical services and adaptively makes the optimal recycling decision for the current network. Subsequent algorithm optimization can start with historical business analysis.  
The complexity of the mixed-recycling algorithm consists of the analysis of historical services and the maximum complexity between Algorithms 1 and 2. To analyze historical services one needs to traverse the historical services twice, of which total amount is N\({}_{\text{hist\_ser}}\). Algorithm 1 has a complexity of O (N\({}_{\text{hist\_ser}}\)), and the complexity of Algorithm 2 is O (V\({}^{2}\)) + O(N\({}_{\text{key}}\)). Thus, mixed-recycling algorithm has a complexity of max[O(N\({}_{\text{hist\_ser}}\)), O(V\({}^{2}\)) + O(N\({}_{\text{key}}\))].