Implementation of Modified GSO Based Magic Cube Keys Generation in Cryptography

Over the last few decades, tremendous and exponential expansion in digital contents together with their applications has emerged. The Internet represents the essential leading factor for this expansion, which provides low-cost communication tools worldwide. However, the main drawback of the Internet is related to security problems. In order to provide secure communication, enormous efforts have been spent in the cryptographic field. Recently, cryptographic algorithms have become essential for increasing information safety. However, these algorithms require random keys and can be regarded as compromised when the random keys are cracked via the attackers. Therefore, it is substantial that the generation of keys should be random and hard to crack. In this paper, this is guaranteed via one of the most efficient nature-inspired algorithms emerged by inspiring the movements of stars, galaxies, and galaxy superclusters in the cosmos that can be utilized with a mathematical model (magic cube) for generating hardly cracking random number keys. In the proposed cryptographic system, the Modified Galactic Swarm Optimization (GSO) algorithm has been utilized in which every row and column of magic cube faces are randomly rotated until reaching the optimal face, and the optimal random elements are selected as optimal key from the optimal face. The generated optimized magic cube keys are used with several versions of RC6 algorithms to encrypt various secret texts. Furthermore, these generated keys are also used for encrypting images using the logical XOR operation. The obtained results of NIST tests proved that the generated keys are random and uncorrelated. Moreover, the security of the proposed cryptographic system was proved.


Introduction
In the modern information world, the utilization of safe data transmitting protocols and cryptographic systems assists in protecting against several attacks on information security [1]. Cryptography represents a scheme in which the information is converted into a non-understood or unreadable style and the encryption and decryption processes are applied using programming algorithms over a digital field [2]. There are two fundamental kinds of cryptographic systems that are based on the utilization of keys; symmetric key and asymmetric key. In the symmetric key cryptographic systems, the sender and receiver share the same secret key to encrypt and decrypt messages. While the asymmetric key cryptographic systems require a pair of keys, the public key of the sender is utilized for encrypting messages, and the private key of the receiver is utilized for decrypting the ciphertext. The data security is based on the complexity and secrecy of the keys. In wide computer networks, compared with symmetric key cryptographic systems, asymmetric key cryptographic systems consume more time and storage space, since both the sender and receiver sides require to store a large number of keys, and utilize a larger amount of computation for encrypting and decrypting messages using different keys [3].
Several metaheuristic algorithms have emerged to search for the optimal potential solution in an acceptable time [4]. Metaheuristic algorithms are created by inspiring various disciplines such as physics, sociology, and biology. Nowadays, the most effective metaheuristic algorithms are inspired by the swarm behavior of biological systems, natural phenomena, and animals [5].
In cryptography, in order to secure the content, a lot of researches concentrate on making the problem of inference very hard. Therefore, metaheuristic algorithms can be utilized for generating random uncorrelated keys in cryptography [6,7].

Literature review and problem statement
Cryptographic systems are needed for securing the transmission of secret information during communication. Day after day, the significance of security is increased owing to the rise of e-commerce and the processing of online transactions. In addition to the algorithms of encryption and decryption, the characteristic of the randomness for the generated key sequences proves the strength of the symmetric key cryptographic systems [7].
The magic cube can be regarded as a cube toy that is separated into distinct sub cubes. These sub cubes can be scrambled using the rotation, which is performed based on specific rules to yield completely different sub cubes. Hence, the concept of the magic cube has been utilized for generating random secret keys to be used for different cryptography and information hiding applications. Most of the researchers used the principle of rotation for shifting every row and column of the faces in the magic cube.
In [8], the transformation of a magic cube was utilized for shuffling the locations of the pixels in an image and modifying the values of the pixels using pseudo-random sequences generated via chaotic maps. In this image cryptography system, the obtained results illustrate that the proposed system is secure and effective enough, and the encrypted images cannot be recognized. While in [9], a system of image encryption in the frequency domain based on rotating the magic cube was proposed. In this system, firstly, the discrete fractional Fourier transform is used for encrypting the image. Secondly, an algorithm of image scrambling using the magic cube rotation and chaotic maps are applied for getting better results, compared to only utilizing the transform domain.
In [10], a system of keys generation and cryptography depending on combining magic cubes hybridization and rotation was presented. There are two processes of rotations implemented in this system. Firstly, generating the key by rotating the magic cube. Secondly, generating the ciphertext by rotating the original text. The obtained results show that the proposed system was secure to some cryptanalysis. In [11], an image cryptography system depending on the 3D magic cube was presented. This proposed system starts with RC6 to separately encrypt multi-images. The encrypted images are encrypted again with the 3D Rubik's cube, in other words, these encrypted images are utilized as faces for the Rubik's cube. The obtained results show that the proposed system is secure and efficient. However, these systems require to exhibit more robustness.
In [12], a system was proposed in which the magic cube is utilized as a 3-dimensional reference in hiding information into grayscale images. The secret information is transformed into the spatial coordinates and the least significant bits of the cover image are substituted regarding these coordinates. The utilization of the magic cube works on only embedding the secret bits via substitution without adding or decreasing the pixel's value, and this leads to avoiding the problem of overflow. While, in [13], a hybrid of the cryptographic and information hiding system was proposed. This hybrid system includes, firstly, generating a secret random key based on a magic cube and chaotic maps, secondly, the generated key is utilized for encrypting an image. Thirdly, the audio cover is utilized for embedding the encrypted image. In this system, in order to generate the random key, the number of iteration and the initial values of chaotic maps are firstly entered, and the obtained numbers are stored in an array. This array is used for filling the magic cube faces and used also for rotating the magic cube and selecting the key. Another information hiding system based on the magic cube key generation was proposed in [14]. In this system, firstly the magic cube based key is generated based on a magic matrix, then, the cover image is separated into non-overlapped blocks. After that, every nine bits from the secret medical data are embedded in each block based on the generated keys. These systems require carrying out more investigations to design better magic cubes to improve image quality.
A few of the above-mentioned related systems successfully elapsed most of the NIST tests, but these systems neglected the principle of finding optimal randomness for the generated magic cube based keys, thus, this important requirement should be achieved. In this paper, this is guaranteed by the Modified GSO algorithm, which is used for selecting an optimal random magic cube based keys.

The aim and objectives of the study
The aim of the proposed system is to generate optimal, random, and uncorrelated keys. The generated key is utilized in the applications of cryptography.
To achieve the aim, the following objectives were set: -to utilize the magic cube to provide a computational hardness for finding the solution; -to utilize the Modified GSO algorithm for selecting an optimal random magic cube based key. This optimization algorithm works in two directions; the first one is to find the optimal face after applying many rows and columns rotations; the second direction is to find the optimal elements within the optimal face, these elements represent the optimal random key; -to encrypt the secret plaintext messages using the Rivest Cipher 6 (RC6) algorithm and encrypt the secret images using the XOR operation depending on the generated keys.

Proposed cryptographic system
This section presents the proposed cryptography system. The proposed system relates between a new metaheuristic algorithm, magic cube, and cryptography. The general diagram of the proposed system is shown in Fig. 1.

Fig. 1. General diagram of the proposed system
The proposed system is based on an optimal magic cube key generation, and it includes several stages. Firstly, the magic cube is constructed and then the modified GSO algorithm is utilized in order to generate optimal random keys, after that, depending on the generated keys, the secret plaintext messages are encrypted by using the RC6 algorithm and secret images are encrypted by using XOR operation.

1. Magic cube generation
In 1974, Ernő Rubik invented the magic cube that originally contains six faces and each face includes nine stickers. Each face can be rotated clockwise or counterclockwise. The magic cube represents a three-dimensional integer's matrices (faces), ordered in the pattern of m×m×m. The essential characteristic of the magic cube is that the summation of the numbers in each row, each column, and main diagonal is equal to a constant number named magic cube constant, indicated by C 3 (m) given as follows: The concept of rotating the magic cube can be utilized for generating random secret keys to be used for different applications of cryptography and steganography. The larger number of rotations leads to the higher complexity of the locations on the magic cube and consequently leads to obtaining random keys.
In the process of magic cube generation, the number of faces and the number of elements in each face are based on the required key length of the encryption process. In order to generate 128-bit, the magic cube includes 6 faces, each face with 9×9. The initialization of each face in the magic cube is done according to equation (6), where the summation of the numbers in each row, each column, and main diagonal is equal to 369, see Fig. 2. The random values shown in Fig. 2 exist on all the faces of magic cube as an example of random selection of numbers.

2. Modified GSO algorithm based magic cube key generation
The behavior of stars within galaxies and galaxies in superclusters under the gravity influence was used in the inspiration of the GSO algorithm. GSO works on taking the advantages of particle swarm optimization (PSO) with the use of flexible multiple cycles of exploration and exploitation levels for finding optimal solutions. It can be applied in various problems of real life owing to its efficiency and simple implementation [15].
In the GSO algorithm, the stars' movement within a galaxy and the galaxies' movement are emulated based on the following rules. Firstly, within each galaxy, stars (individuals) are attracted to better ones (optimal solutions). This process of attraction is applied by utilizing the algorithm of PSO. Secondly, to all galaxies, the global bests are selected to be treated as a super swarm. The PSO is also utilized to perform the motion of particles in the super swarm.
The GSO algorithm includes several significant controlling parameters to be utilized in each level. The population or swarm (supercluster of galaxies) consists of N parti-tions (galaxies of stars) named sub-swarms : 1, 2, , , i S S i N ⊂ = … which include n elements or stars ( ) : 1, 2, , , The initialization of each star is generated randomly inside the search space [s Minimum , s Maximum ] dim .
At level-1 of the GSO algorithm, the algorithm of PSO is performed independently to every sub swarm, thus, PSO should be run N times. Each sub swarm holds an associated global best gb (i) , and this gb (i) can be updated when one of its personal bests ( ) i j pb takes a value of minimal function than gb (i) , where O is the objective function. Stars in every sub swarm are attracted randomly to the local minimum (optimal solution) reached via that certain sub swarm. The motion of a sub swarm is independent without influence on the other sub swarms, hence, giving potential comprehensive and unaffected search. In order to obtain the whole interest of exploration capability of multi-sub swarms, galactic best gb is updated when any global best gb (i) supposes a value of the preferable function, GSO can keep a record for its suitable solution through updating gb.
Every sub swarm explores independently the search space on its own. The iteration starts by calculating the velocity ( ) i j v and location of stars. The following expressions explain the updating of the star's velocity and location: where w 1 is the inertia weight, cc 1 and cc 2 are the coefficients of acceleration for PSO, rand 1 and rand 2 represent random numbers within -1, and 1. At level-2 of the GSO algorithm, the global bests are involved to compose superclusters. In the same way, the new super swarm is generated through the aggregation of the global bests from sub swarms.
where; l (i) is the location of super swarm i, N is the number of sub-swarms, l (i) =gb (i) . The vectors of velocity and location are updated as follows: , where w 2 is the inertia weight, cc 3 and cc 4 are the coefficients of acceleration for PSO, rand 3 and rand 4 represent random numbers within -1, and 1. At this level, gb denotes as the global best sample and this gb will not be updated until the search specified the preferable point. As the super swarm focuses on the global bests from sub swarm, it is capable of enhancing the exploitation. The location of galactic best after the last epoch gb and its value of evaluation O(gb) are returning as minimum cost and location, respectively by the algorithm.
In the original GSO algorithm, the first level starts with finding the optimal stars in all the galaxies, after that, in the second level, the optimal galaxy is selected. This strategy will lead to losing a lot of time. In this proposed system, we will modify this strategy to be suitable to cope with our problem and prevent time wasting by selecting the optimal galaxy then selecting the optimal stars where the galaxies represent the faces of the magic cube, and the stars represent the elements in each face. Fig. 3 shows an example of this modified strategy. The modified GSO strategy based magic cube works as follows: -modified GSO parameter initialization; -at Level-One, in order to decrease the opportunity of pattern prediction by the cryptanalysts, thus, randomly rotating every row and column of magic cube faces, and selecting the optimal face (galaxy) according to equations (5) and (6); -at Level-Two, within the optimally selected face, the PSO works on finding the optimal elements, which represent the optimal key by using equations (2) and (3).

3. Processes of cryptography
In this stage, the obtained optimal random key bits are used with several versions of RC6 algorithms to encrypt and decrypt various plain texts.
RC6 algorithm represents a symmetric key block cipher. In general, it holds several variable parameters like block size, number of rounds, and key size. Particularly, the RC6 encryption algorithm is designed as RC6 (d, n, l), where d represents the size of the word (each block includes four words), n represents the number of rounds and l represents the length of the secret key in bytes. Besides the standardized RC6, there are various versions of RC6 that are capable of working on the block size equal to 128 bits using 28 bits, 192 bits, …, 2,040 bits of key sizes.
In the RC6encryption algorithm, firstly, a process of expanding the secret key to an array of 2n+4 secret d-bit words S k in accordance with the algorithm of key scheduling is carried out. Suppose (W, X, Y, Z) represent the plaintext involving four d-bit words. Point out that a d-bit word is identically described as a Modular Arithmetic (integer modulo 2 d ). After that, the encryption algorithm is specified as explained in Fig. 3.

Fig. 3. RC6 encryption algorithm
Where ⊕ is the operation of bit-wise Exclusive OR, «A<<B» represents the rotation of A to the left via the log 2 d least significant bits of B, and f represents the function that holds the role of a pseudorandom generator given by: The cipher text represents (W, X, Y, Z) and every round n includes precisely two sub-keys S k .
Furthermore, in this stage, the optimal generated keys are also used for encrypting grayscale and color images using the logical XOR operation.
The Suite of NIST tests are utilized for checking the randomness of the generated cryptographic key, these tests represent ten statistical tests. Table 1 explains the obtained results of NIST tests for the generated binary key bits. The generated optimal random keys are utilized in texts and images cryptography. In the application of texts cryptography, the secrecy of ciphers can be computed in terms of the key equivocation (conditional entropy of key given cipher). Table 2 shows the plain texts, the obtained cipher texts of variable lengths using RC6 with the optimal generated key, and the average security for obtained cipher texts using the optimal generated key and using randomly selected key from the magic cube.
The RC6 algorithm has been improved using the generated key regardless of the size of plain text.
In the application of images cryptography, several images of size (256×256) have been utilized to be encrypted using XOR operation. Fig. 5 shows the obtained encrypted images with their histograms.
The histogram describes the intensity distribution of the image. It represents a visual tool that is utilized for seeking the ultimate relationship between the original and encrypted distributions of images. So, the histogram of encrypted images should be flat and uniformly distributed. Here, the obtained histograms of encrypted images are equally distributed.
Besides the utilization of peak signal to noise ratio (PSNR) as an evaluation criterion for image quality, it can be utilized for finding the closeness between the encrypted and the original images. Additionally, the Correlation Coefficient can be utilized for the same purposes. Table 3 shows the results of PSNR and Cross Correlation for encrypted images using the optimal generated key and using a randomly selected key from the magic cube. Whenever the values of PSNR are lower, the higher the difference between the original and the encrypted images, resulting in a more secure image cryptography system. And in the criterion of Correlation Coefficient, a correlation of -1.0 shows a perfect negative correlation, while a correlation of 1.0 shows a perfect positive correlation.

Discussion of the proposed system
The magic cube-based issue provides a computational hardness for obtaining the solution, subsequently, attackers are facing difficulty to reach a solution for the scrambled magic cube since it can find more possibilities in the mathematical functions form like factorial and exponential. In this paper, the Modified GSO algorithm has been exploited for randomly rotating the faces of the magic cube to find the optimal face, and the optimal random key is obtained from the optimal face. The obtained results of NIST tests demonstrate that the generated random keys successfully passed all NIST tests. These generated keys are utilized in texts and images cryptography.
The obtained results of average security from the experiments point out that the proposed text cryptography system achieves high results.
In order to evaluate the proposed image cryptography system, the histogram of both original and encrypted images was calculated. As previously seen from the histograms in Fig. 5, the histograms of original images have a tilted structure analogous to the original images, however, the histograms of the encrypted images are uniformly distributed and flat. Consequently, statistical attacks utilizing the information of histograms are impossible. Moreover, the values of PSNR of Lena, Trees, Peppers, and Baboon images encryption are tested. The obtained results of small PSNR values demonstrate that the original and encrypted images have considerable differences. Another measurement of evaluation is the correlation coefficient. The experimental results demonstrate that the encrypted images have very low correlations. Therefore, the proposed image cryptography system is efficient and secure. In this paper, the optimization algorithm was implemented only on a magic cube.
In future works, we can develop a new optimization algorithm based on the magic rectangle with m dimensions, and present a symmetric cipher based on this optimized magic rectangle key.

Conclusions
1. The mathematical phenomenon (magic cube) can be successfully created as an extension to the mathematical magic square.
2. The obtained results of NIST tests explain that the generated optimized magic cube based key is random with no correlation.
3. The RC6 algorithm has been improved using the generated key regardless of the size of plain text. Also, the RC6 algorithm has been improved by utilizing the optimal keys of the magic cube regardless of the key length. Furthermore, the image cryptography algorithm based on the generated keys has higher security and the obtained results of average PSNR and Correlation Coefficient for the encrypted images are 7.613156, and 0.5554, respectively.