## 4 The SEME-TDHM Algorithm
### Encryption Process
Figure 9 provides an example containing 5 \(\times\) 5 images with the steps outlined below;  
```
Input: pixel matrix _P1_ after single-channel scrambling, random sequence _uu1_ and _uu2_, sequence _s1_ with index 1 to _3N_, sequence _s2_ with index 1 to \(M\)  c = _P1_(1,:);  sorted_c = c(:_s1_); _P1_(1,:) = sorted_c; for i = 2:M  s3 = ctrishift(s1,uu1(i-1));  c = _P1_(i,:);  sorted_c = c(:_s3_); _P1_(i,:) = sorted_c; end  d = _P1_(:1);  sorted_d = d(s2,:); _P1_(:1) = sorted_d; for i = 2:3 \(\times\) N  s4 = ctrishift(s2,uu2(i - 1));  d = _P1_(:i);  sorted_d = d(s4,:); _P1_(:,i) = sorted_d;  end Output: matrix _P1_ obtained after row global transformation
```  
**Algorithm 1**Global Scramble  
```
Input: pixel matrix _P1_ after single-channel scrambling, random sequence _uu1_ and _uu2_, sequence _s1_ with index 1 to _3N_, sequence _s2_ with index 1 to \(M\)  c = _P1_(1,:);  sorted_c = c(:_s1_); _P1_(1,:) = sorted_c; for i = 2:M  s3 = ctrishift(s1,uu1(i-1));  c = _P1_(:,:);  sorted_c = c(:_s3_); _P1_(i,:) = sorted_c; end  d = _P1_(:1);  sorted_d = d(s2,:); _P1_(:,1) = sorted_d; for i = 2:3 \(\times\) N  s4 = ctrishift(s2,uu2(i - 1));  d = _P1_(:,i);  sorted_d = d(s4,:); _P1_(:,i) = sorted_d; end Output: matrix _P1_ obtained after row global transformation
```  
**Algorithm 2**Global Scramble  
```
Input: pixel matrix _P1_ after single-channel scrambling, random sequence _uu1_ and _uu2_, sequence _s1_ with index 1 to _3N_, sequence _s2_ with index 1 to \(M\)  c = _P1_(1,:);  sorted_c = c(:_s1_); _P1_(1,:) = sorted_c; for i = 2:M  s3 = ctrishift(s1,uu1(i-1));  c = _P1_(:,:);  sorted_c = c(:_s3_); _P1_(i,:) = sorted_c; end  d = _P1_(:,1);  sorted_d = d(s2,:)* [Step7] Local cross-diffusion: The positions of the elements in matrix \(A11\) with values 1 and 2 are identified and the elements at the corresponding positions in \(A1\) perform XOR operation with \(A2\) and \(A3\), respectively. As shown in Algorithm 2, \(A12\) then locates the positions of 0 and 2, where _indices_i_ (\(i=0\), 1, 2) denotes where \(i\) is located. \(A13\) locates the position of 0 and 1;
* [Step8] Pixel-level global diffusion: Employ the chaotic system to generate three \(M\times N\) chaotic matrices, namely \(x1\), \(y1\), and \(z1\). XOR the pixels of \(A1\) with those of \(A2\) and \(x1\), XOR the pixels of \(A2\) with those of \(A3\) and \(y1\). XOR the pixels of \(A3\) with those of \(A1\) and \(z1\);
* Bit-level global diffusion: Convert \(A1\), \(A2\), and \(A3\) into 8-bit binary sequences, then combine them into an \(M\times 24N\) matrix labeled \(PA\). The specific process of diffusion is shown as Equation (9):

Figure 9: Global scrambling. \[\left\{ \begin{array}{l}PA(i,:)\stackrel{{ shift\; right\; by\;i\; units}}{{\rightarrow}}PA(i,:),i\in[1,M-1],\\ PA(i,:)\stackrel{{ shift\;right\;by\;i\; units}}{{\rightarrow}}PA(i,:),i=M,\\ PA(:,j)\stackrel{{ shift\;up\; upward\;by\;units}}{{ \rightarrow}}PA(:,j),j\in[1,12\times N],\\ PA(:,j)\stackrel{{ shift\;up\; upward\;by\;j-12\times N\;units}}PA(:,j),j\in[12 \times N+1,24\times N]\end{array} \right. \tag{9}\]

Step10.Finally, each element is converted into a decimal number by incorporating the respective weights, and the results are stored in the \(P2\) matrix. These calculations complete the conversion of the encrypted image. ### Decryption Process

The decryption process is the inverse of the encryption process, and its primary processes are as follows:

1. Bit-level global inverse diffusion: The image is transformed into a binary image matrix, which is subjected to vertical counter-diffusion and horizontal counter-diffusion in the opposite direction to the encryption process;
2. Pixel-level global inverse diffusion: Employ the same method as in pixel-level global diffusion but from the third-pixel block onwards, proceeding sequentially;
3. Local Cross counter diffusion: Local counter-diffusion aligns with the encryption process;
4.