# A Novel Hybrid Elementary Cellular Automata and Its Application in a Stream Cipher
## 4 Stream Cipher Based on HECA-M  
### Description of Proposed Stream Cipher  
The proposed stream cipher consists of a HECA-M, a HASH function (SHA-512 algorithm), and a buffer with the output controller. The HASH function is utilized to initialize the status value of HECA-M, including the driving part, the mask part, and the rule groups. The HECA-M is operated to generate the original keystream. Meanwhile, the length of the cell space in this HECA-M is 256. A constant IV generated randomly and a secret key with 512 or 256 bits are the input. Moreover, the original keystream is processed by the buffer to output the final keystream. The result of the HASH function controls the buffer. The structure of the proposed stream cipher is depicted in Figure 6.  
The procedure of the proposed stream cipher (Algorithm 1) is listed as follows:  
``` Step 1: Initialize variables Input: secret_key \(K\) (256 bits or 512 bits), constant_vector \(IV\) (256 bits) Step 2: Determine chaotic rule group and initialize HECA-M idx = Hamming (\(K\), \(IV\))  chaotic_rule_group (\(m\), \(r1\), \(r0\)) = LUT (idx) (From Table 5)  inv = SHA512 (\(K\), \(IV\)) (\(inv\_d\), \(inv\_m\)) = inv Step 3: Initialize HECA-M The ECA of driver part \(\leftarrow\)\(inv\_d\),\(r1\),\(r0\)  The ECA of MASK part \(\leftarrow\)\(inv\_m\),\(rm\)  Step 4: Generate original keystream  Iterate HECA-M to generate the original_keystream Step 5: Using buffer to generate final keystream \(n_{0}\) = bin2 dec(middle_10_bits_of(inv))  Remove first \(n_{0}\) iterations from original_keystream \(flag\) = Hamming(\(inv\)) % 2  If flag == 0: final_keystream\(\leftarrow\)Select sequences generated by cells with even indexes from original_keystream Else: final_keystream\(\leftarrow\)Select sequences generated by cells with odd indexes from original_keystream Output: final_keystream

Figure 6: The structure of the proposed stream cipher. Give a secret key and get a constant vector IV

The secret key \(K\) with 256 bits or 512 bits is given by the user. The constant \(I\!V\) with 256 bits is generated randomly by the computer, and it is utilized to avoid the initial null value of the HECA-M, such as zeros or ones with 512 bits. Meanwhile, \(I\!V\) can be employed in the handshake between two sides of the communication. Get a chaotic rule group and initialize the HECA-M

The choice of a chaotic rule group is determined by the Hamming weight of \(K\) and \(I\!V\), which is represented as follows:

\[idx=\text{Hamming}(\mathbf{K},\mathbf{IV})\bmod 27+1, \tag{4}\]

where \(idx\) represents the index of the chaotic rule group. The function \(\text{Hamming}(\mathbf{K},\mathbf{IV})\) is to acquire the Hamming weight of the binary vector consisting of \(\mathbf{K}\) and \(\mathbf{IV}\). Then, a chaotic rule group \((rm,r1,r0)\) with index \(idx\) can be obtained from LUT (Table 5). The initial value of HECA-M is the output of the HASH function SHA-512, which is calculated as follows:

\[\left\{ \begin{array}{l}\mathbf{inv}=\text{SHA512}(\mathbf{K},\mathbf{IV})\\ \mathbf{inv}\_\mathbf{d}\_\mathbf{inv}(1:256)\\ \mathbf{inv}\_\mathbf{m}\_\mathbf{inv}(257:512)\end{array} \right., \tag{5}\]

where \(\text{SHA512}(\bullet)\) indicates the HASH function. \(\mathbf{inv}\) represents the HASH of \((\mathbf{K},\mathbf{IV})\), that is, the initial value of the HECA-M with a length of 512 bits. Meanwhile, \(\mathbf{inv}\) is divided into two parts: \(\mathbf{inv}\_\mathbf{d}\) and \(\mathbf{inv}\_\mathbf{m}\). Additionally, they are regarded as the initial values of the driving and mask parts, respectively. Generate original keystream

The initial value and chaotic rule group of the HECA-M have been acquired after _Step 2_. Then, the HECA-M is iterated to generate the original keystream. There are 256 cells in the driving part. Thus, the HECA-M can generate 256 sequences with the same length simultaneously. Process the original keystream by the buffer and generate the final keystream

The buffer is controlled by the initial value of the HECA-M, which is the HASH function's result.