# Advancement of the DRPE Encryption Algorithm for Phase CGHs by Random Pixel Shuffling
## 3 From the Synthesis of a 3D Scene to Its Safe Reception: Process Description
### Encryption of the CGH  
Figure 3a shows a flowchart for key generation and CGH encryption. The proposed method involves applying the DRPE algorithm for phase modification and pixel shuffling of the CGH. We will see that pixel shuffling creates a combinatorial explosion that is difficult to attack by brute force. Additionally, phase modification adds an extra layer of encryption to the information stored in the CGH. This stage corresponds to Figure 1c.  
To select a truly random key, a cryptographically secure pseudorandom number generator (CSPRNG) must be used. In this work, the random function from MATLAB's System.Security.Cryptography library has been used.  
These numbers are used as a random index to feed the Fisher-Yates algorithm [42], which is a classic algorithm for randomly and securely shuffling a set of elements. It works by traversing the elements of a vector in reverse order and generating a random index \(j\) (obtained by CSPRNG)) for each element \(i\), such that \(0\leq j\leq i\), with \(i\) being the index of the element being modified at each step. Finally, the elements \(i\) and \(j\) are swapped in position.  
This information is stored in the Random Sorting Vector (RSV) of size \(Z=M\times N\) (Figure 3a). The encryption process uses the phase matrix of the CGH, stored in a PNG file, to convert it into a CGH-PV of size \(Z=M\times N\). Using the shuffling RSV, the positions of the CGH-PV are changed, resulting in the Shuffled Phase Vector (SPV).  
From the RSV, a phase mask vector can be obtained through a truncation operation.  
\[PRV[i]=RSV[i]\%256\quad\forall\quad i\in\{1,\dots,Z\} \tag{1}\]  
It is necessary to ensure that the values are within range through a modulo operation.  
Figure 2: Initial scene. (**a**) is the designed scene. (**b**) represents the phase information of the CGH encoded in a PNG image for subsequent transmission to an SLM.  
Depending on the required security level, the phase mask can be generated from the shuffling vector through a modulo operation on this vector, both in the encryption phase and in the decryption phase, or with a separate procedure.  
This vector is added to the SPV to modify the phase pattern, resulting in the Shuffled and Phase Changed Vector (SPCV).  
\[SPCV[i]=(SPV[i]+PRV[i])\%256\quad\forall\quad i\in\{1,\dots,Z\} \tag{2}\]  
The SPCV is reordered to recover a matrix of size \(M\times N\), which will be the ciphertext to be sent to a receiver.  
The result of the encrypted CGH obtained (the ciphertext) is shown in Figure 3(a), and the image obtained with an incorrect key is shown in Figure 3(b). As we will see in Section 4, the histogram of Figure 3(b) is nearly uniform.  
Figure 4: Encrypted CGH. (**a**) shows the phase distribution after the encryption operations have been performed. (**b**) is the image obtained from the CGH without using a key or with a wrong key.  
Figure 3: Flowcharts of the CGH encryption and decryption process. In orange, the files that can be visualized on an SLM are indicated; in red, the keys generated for shuffling and creating the phase mask; in blue, the algorithms or procedures used; and in green, the vectors generated from the previous files and algorithms.