# Enhancing Visual Data Security: A Novel FSM-Based Image Encryption and Decryption Methodology
## 3 Materials and Methods
### Encryption Algorithm Using Finite State Machines  
In the initial phase of the encryption process, the file undergoes processing by a permutation machine, followed by encryption utilizing a weakly invertible state machine. Specifically, a permutation state machine, serving as an automaton, orchestrates the rearrangement of characters within the input string based on predefined permutation rules. As the permutation state machine is integral to the decryption procedure, its invertible is imperative. To achieve this, we employed an invertible finite automaton possessing the right invertibility. The requisite condition for right invertibility mandates that the automaton mapping \(X_{a}\) be surjective for any initial state 'a'. In other words, it is both necessary and sufficient for each row of the output table to encompass occurrences of every output signal at least once [34]. The program incorporates a module dedicated to the generation of finite-state machines. It is emphasized that the quantity of finite automata within this framework, characterized by \(n\) states, \(x\) input symbols, and \(y\) output symbols, follows a combinatorial expression of \((n\times y)^{n\times x}\)[35]. It is acknowledged that not all automata within this classification exhibit invertibility. Consequently, an algorithm designed to verify invertibility is employed to ascertain the membership of a given finite automaton within the category of invertible finite automata. Subsequently, the produced automata undergo an assessment for invertibility utilizing the Kohavi algorithm [36; 37]. The invertibility testing module facilitates the construction of a repository comprising invertible finite state machines. Subsequently, these machines are deployed for the encryption of the file. Per Theorem 1 presented in Article [35] and Theorem 1.4.1 elucidated in Book [15], a finite automaton attains invertibility if and only if its associated graph is devoid of cycles. The algorithm employed for verifying invertibility encompasses the following sequential steps [36]:  
1. Consider a finite automaton denoted as \(M=<X,Y,S,\delta,\lambda>\), represented in the format of a state table. In this context, both \(X\) and \(Y\) are elements of the set \(\{0,1\}\);
2. A testing table (TTab) is constructed, consisting of \(2\) parts; * Upper part of TTab: The state table of the finite state machine is rewritten; the rows in the upper part of the table correspond to the states of the machine, and the columns to the output symbols. The entry at the intersection of row \(s_{i}\) and column \(y_{m}\) are states that can be reached from state \(s_{i}\) using a single transition associated with the output symbol \(y_{m}\). The entire upper half of the table is actually a list of the next states of the machine and is therefore called the output table; * Bottom of the TTab: Each compatible state pair appearing at the top becomes the row header of the bottom of the testing table. The next states of these pairs are: they consist of all implied joint pairs. Any implied pair of states that have not already been used as a row header becomes the row header, its next state being found in the same way. The process terminates when all compatible state pairs have been used as row headers;A testing-oriented weighted graph G, according to TTab, is constructed using the steps as follows:  
* Each compatible pair of states \(s_{i}s_{j}\) corresponds to a vertex in G;
* An arc labeled \(y_{m}\) goes from vertex \(s_{i}s_{j}\) to vertex \(s_{p}s_{q}\), where \(p\
eq q\), if and only if the compatible pair (\(s_{p}s_{q}\)) is the next state of the compatible pair (\(s_{i}s_{j}\));
* Determine the ratio of the original finite state machine to the group of invertible finite state machines with memory and find its delay. * The graph G from Step 3 is checked for the presence of a cycle.