# Hide45: A Method for Optimal Payload Data Hiding in Base45 Encoded Strings
## 5 Proposed Algorithm
### Encoding and Decoding Algorithms  
The encoding and decoding algorithms of our proposed **Hide45** method make use of a table \(EncDec\) that implements the mappings \(\mu\) and \(\eta\). \(EncDec\) contains a row (i.e., a record) for every binary string in \(\mathcal{B}\) and its corresponding sequence in \(\mathcal{W}\): this realizes the one-to-one function \(\mu\) (and its inverse \(\mu^{-1}\)) in Figure 1.  
Table 1 reports the two types of record needed by the table \(EncDec\) to store the information for the encoding and the decoding: a Type 1 record is used for sequences carrying no payload bits, that is sequences in \(\mathcal{W}-\mathcal{E}\). On the other hand, a Type 2 record is used for a binary string that is mapped by \(\mu\) to a sequence \(\mathsf{S}_{0}\) in \(\mathcal{E}\) that is capable of carrying payload bits, e.g., \(k\) bits: in this case \(\mathsf{S}_{0}\) and other \(2^{k}-1\) sequences in \(\mathcal{D}\) make up an ordered list \(\left[\mathsf{S}_{0},\mathsf{S}_{1},\mathsf{S}_{2},\ldots,\mathsf{S}_{2^{k}-1}\right]\) that can be indexed by the value expressed by the \(k\) bits to reversibly encode them. Function \(\eta\) (Figure 2) operates in this way: if the \(k\) bits have value \(i\) then \(\eta\) outputs \(\mathsf{S}_{i}\) in place of \(\mathsf{S}_{0}\); given \(\mathsf{S}_{i}\) in \(\left[\mathsf{S}_{0},\mathsf{S}_{1},\mathsf{S}_{2},\ldots,\mathsf{S}_{2^{k}-1}\right]\) its inverse \(\eta^{-1}\) returns \(k\) bits valued \(i\) and the sequence \(\mathsf{S}_{0}\). It is obvious that:  
* \(EncDec\) is composed of \(2^{n}\!=\!2^{16}\) rows;
* The sequences in the last column of \(EncDec\) form a partition of \(\mathcal{S}\). The **encoding procedure** has as input the stream of payload data bits to be embedded and processes one binary string \(\mathsf{B}\in\mathcal{B}\) at a time to be converted in printable form as follows:
* If \(\mathsf{S}_{0}=\mu(\mathsf{B})\in\mathcal{W}-\mathcal{E}\) (Type 1 entry in \(EncDec\)) then no payload bits can be embedded and \(\mathsf{S}_{0}\) is output;
* Otherwise \(\mathsf{S}_{0}=\mu(\mathsf{B})\in\mathcal{E}\), thus its Type 2 entry in \(EncDec\) is used getting \(k\), the number of bits that can be stored with \(\mathsf{S}_{0}\), and \(k\) payload bits are read from the stream whose decimal value \(f\) is used as an index by \(\eta\) to select and output the sequence \(\mathsf{S}_{f}\) from the list \(\left[\mathsf{S}_{0},\mathsf{S}_{1},\mathsf{S}_{2},\ldots,\mathsf{S}_{2^{k}-1}\right]\) found in the corresponding entry. The **decoding procedure** performs the inverse mapping and extraction working on an input sequence \(\mathsf{S}\in\mathcal{S}\) after the other to obtain the original data in binary form and the payload bits:
* If \(\mathsf{S}\) is associated to a Type 1 entry in \(EncDec\) then no payload data is stored and the binary string \(\mathsf{B}=\mu^{-1}(\mathsf{S})\) is output;
* Otherwise \(\mathsf{S}\) is searched in the last field of the Type 2 entries of \(EncDec\): when found, its index in the list is used to recover the \(k\) payload bits and the corresponding sequence \(\mathsf{S}_{0}=\eta^{-1}(\mathsf{S})\in\mathcal{E}\) is used to output \(\mathsf{B}=\mu^{-1}(\mathsf{S}_{0})\).