Magic cube puzzle approach for image encryption

image. The encrypted image is composed of arbitrary patterns that do not provide any clues about the plain image and its cipher key. Ideally, the encrypted image is entirely independent of its plain image. Many functions can be used to achieve this goal. Based on the functions used, image encryption techniques are categorized into: (1) Block-based; (2) Chaotic-based; (3) Transformation-based; (4) Conventional-based; and (5) Miscellaneous based. This study proposes a magic cube puzzle approach to encrypt an 8-bit grayscale image. This approach transforms a plain image into a particular size magic cube puzzle, which is consists of a set of blocks. The magic cube puzzle algorithm will diffuse the pixels of the plain image as in a Rubik’s Cube game, by rotating each block in a particular direction called the transposition orientation. The block’s transposition orientation is used as the key seed, while the generation of the cipher key uses a random permutation of the key seed with a certain key length. Several performance metrics have been used to assess the goals, and the results have been compared to several standard encryption methods. This study showed that the proposed method was better than the other methods, except for entropy metrics. For further studies, modification of the method will be carried out in such a way as to be able to increase its entropy value to very close to 8 and its application to true color images. In essence, the magic cube puzzle approach has a large space for pixel diffusion that is possibly supposed to get bigger as a series of data has transformed into several magic cubes. Then, each magic cube has transposed with a different technique. This proposed approach is expected to add to a wealth of knowledge in the field of data encryption.


291
International Journal of Advances in Intelligent Informatics ISSN 2442-6571 Vol. 6, No. 3, November 2020, pp. 290-302 Gaffar et al. (Magic cube puzzle approach for image encryption) assessment of the encryption goodness depends on how messy (incomprehensible) the encrypted data is. The critical points are in the encryption algorithm and the generation of the cipher key used.
There are two modes of the encryption process: (1) block cipher; and (2) stream cipher. Block ciphers consist of encryption and decryption algorithms, where the decryption algorithm is the inverse of the encryption algorithm. In order to make the block cipher secure, a cipher key is made as random as possible using random permutations of a certain length. In the case of key lengths, block cipher security also depends on determining block size. Stream ciphers are symmetric ciphers where each digit of the plaintext is encrypted one by one with the corresponding keystream digits. A keystream is a pseudorandom stream of alphabetical digits combined with plain/ciphertext [2] [28].
In principle, various kinds of encryption methods are classified into two, namely: (1). Random based; (2). Constant based. Random based encryption algorithm consists of deterministic and heuristic methods. Deterministic methods produce ciphertext uniquely based on its plain text, whereas the heuristic method generates ciphertext by using random values. Included types are machine learningbased encryption methods. A constant-based encryption algorithm emphasizes numerical constant values (especially the hash method and symmetric encryption). These values must be reasonable and not contain back doors [2] [29]. Some techniques usually used in deterministic methods are: (1). Transposition; (2). Substitution; (3). They are combined both. The transposition technique is an encryption technique that changes the plaintext's character arrangement without changing the original character [30]- [32]. And vice versa for substitution techniques [24] [30][32]- [35].
Image encryption is encoding images into a difficult format to understand using several cryptographic algorithms and a cipher key visually. In contrast, decryption of images is to decode encrypted images into their original format. Not all traditional cryptographic algorithms can be used to encrypt the image because the image has adjacent pixels that are highly correlated [36]. Two essential properties that must be possessed by a suitable image cryptosystem are diffusion and confusion. diffusion is used to increase the occurrence of zero correlation between plain image and cipher image such that the image cipher cannot be recognized. Confusion is used to create a clueless image cipher. It means that the cipher key is related to plain image through non-simple ways [37]. Many functions can be used to achieve this, such as permutation, scrambling, substitution, chaotic functions, etc. Based on the functions used, image encryption techniques are categorized into: (1). Block-based [38], (2). Chaotic-based [15] [39]; (3). transformation-based [40]; (4). Conventional-based; (5). miscellaneous-based [41].
Many image encryption algorithms have developed with the aim of not only protecting all visual information but also enough from attempts at cryptanalyst attacks. In this case, the image encryption algorithm should have the following characteristics: (1). Cipher image must not depend directly on a plain image; (2). Key-streams are built from the concept of the relationship between plain image and cipher image, which is very difficult to guess; (3). The encryption algorithm operates on a long cipher keyspace to prevent brute force attacks; (4). The correlation between a plain image and cipher image is close to zero; (5). Cipher images must not contain any information about the plain image and its passkey; (6). Cipher images must contain high disturbances and are visually unpredictable. In summary, an encrypted image (cipher image) consists of arbitrary patterns that do not provide any clues about the plain image and its cipher key. The encrypted image is entirely independent of its plain image. Some performance metrics commonly used to assess an image encryption algorithm's merit are: (1). The correlation coefficient between plain and encrypted images; (2). Bit length metric of the cipher key; (3). Histogram deviation; (4). Information entropy; (5). NPCR (Number of Pixels Changing Rate) and UACI (Unified Averaged Changed Intensity); (6). PSNR (Peak signal-to-noise ratio) between plain and encrypted images [1] [36][37] [41].
This study proposes a magic cube puzzle approach to encrypt images. This approach transforms a plain image into a particular size magic cube, consisting of a set of blocks. The magic cube puzzle algorithm will diffuse a plain image pixel like in a Rubik's Cube game by rotating each block in a particular direction. The number of rotations in a particular direction is used as the cipher key.

Composing the magic cube
A magic cube consists of a set of blocks of the same size to form a cube. A magic cube of × ×size requires some S-sized × blocks. To build a magic cube of a specific size requires as much data as a block of the magic cube. In general, the proposed method is shown in Fig. 1. The transposition stage is considered as the encryption stage, while the reposition stage is the decryption stage.
Suppose an 8-bit grayscale image has a row-column size × . Each block is set to × size. The number of magic cubes needed is = (( × )/ 3 ) + 1. All pixels are placed in each block. The remaining empty blocks of × − filled with random numbers within the range 0..255. Suppose an 8-bit grayscale image stated by: Pixel composition in stream form expressed by:

Transposition the magic cube
This study uses a rotation angle of transposition ±90°. In principle, the magic cube has three side views ( , , ) as shown in Fig. 4. Each side display has three transposition orientations where each orientation can be positive and negative, so there will be a 3 × 2 number of transposition orientations. If all transposition orientations are arranged sequentially (( → ), ( → ), ( → ), ( → ), ( → ), ( → )), then this arrangement is considered as the key seed (1, 2, 3, 4, 5, 6). Each side view has S blocks, so there will be several orientation transpositions = 2 × 3 × . Hence, key seed can be stated by ( , ) where is the index number of transposition orientation ( = 1 … ) and j is the index number of block ( = 1 … 6). Generation of the key seed using random permutation. It also indicates that the key length should be more than 6. If the number of k key lengths of each block is specified, the number of permutations of k key lengths of each block expressed by [42]:  Because the total number of key length is × , then keyspace is stated by 2 × . The cipher key with length k will contain the order of transposition orientation according to the magic cube block number. To achieve good image encryption, it must meet ℎ > 2 100 [41]. Hence, it must meet 2 × > 2 100 . To fulfill this requirement, determining the cipher key lengths of each block and block size is very important. The magic cube transposition algorithm is shown in Fig. 7.

Image decryption
The encrypted image was transformed into pixel streams. A number of the × × -sized transposed magic cube composed from pixel streams in sequence ( ℎ ( ) ). The reposition stage is carried out for each transposed magic cube using a cipher key descending in order. The all repositioned magic cubes transformed into pixel streams in sequence ( ( ) ). Finally, the decrypted image is built from × pixels of its pixel streams.

Performance measurement
Evaluation of an image encryption algorithm's performance is related to several characteristics that need to be considered. Various performance metrics commonly used are to assess the independence of an encrypted image against its plain image. Encrypted images do not provide any clues about the plain image and its cipher key. This section outlines some of the performance metrics used in this study.

Keyspace metric
An encrypted image's essential feature is the key's sensitivity and the initial parameters used to generate it. A keyspace is the limit of all possible cipher keys of a certain length generated randomly. Large keyspace can reduce brute force attacks. A keyspace is mathematically expressed by [41][43]: where key-length is the total number of bits in the key, commonly, cipher key longer than 100 bits prevents brute force attacks.

Correlation metric
A good encryption technique must produce an encrypted image with a correlation close to zero between pixels adjacent to each other. Commonly, a correlation test was performed on each pair of horizontal, vertical, and diagonal pixels between an encrypted image and a plain image [41] [43]. Suppose there is a series of X and Y, where = { 1 , … , }, = { 1 , … , }, n is the number of data. Correlation between them stated by:

Differential metric
Sensitivity to pixel changes between an encrypted image and its plain image is measured using NPCR (Number of Pixels Changing Rate) and UACI (Unified Averaging Changed Intensity) [37] [43]. Suppose is a plain image and ℎ is an encrypted image with × size. NPCR stated by: UACI stated by:

Information Entropy metric
Entropy is a measure of the uncertainty of a random variable. A gray image can be interpreted as a sample emitted from a source with an intensity of {0 ... 256}. We can model these intensity values using a gray image histogram and produce an estimate of source entropy [43]- [45]. The entropy of a gray image X is expressed by:

297
International Journal of Advances in Intelligent Informatics ISSN 2442-6571 Vol. 6, No. 3, November 2020, pp. 290-302 where is the probability of the intensity value of the i index, and ( ) is the entropy value of the gray image X. An entirely random 8-bit grayscale image has an entropy value of 8. This value shows the maximum diffusion of evenly spread pixels with a probability of pixel intensity of 1/256.

PSNR (Peak Signal to Noise Ratio) metric
An encrypted image can be considered as a plain image exposed to noise. The amount of noise that is measured using PSNR expressed by:

Results and Discussion
This study was used a face image dataset obtained from https://www.kaggle.com/datasets, and the selected face image data converted into a grayscale image. All 8-bit grayscale image samples are 225x225 in size. The results are shown in Table 1. each block that has used was 11, with the number of blocks of the magic cube was 75. Hence, the cipher key length was 11 × 75 = 825, and the keyspace of 2 825 . The study results were compared with several standard encryption methods (Vigenere, RC4, DES, 3DES, AES) with the results obtained from [37]. A comparison of image encryption results between the proposed method with some standard encryption algorithms has shown in Fig. 8. The results of performance comparisons successively have shown in Table 2 to Table 6  To achieve good image encryption, it must meet ℎ > 2 100 . Table 2 shows the comparison of the key length and keyspace of the proposed method and other methods. The proposed method has a much larger key length and keyspace than the other methods (key length = 825, keyspace = 2825). This means that the proposed method has the best resistance to brute force attacks compared to other methods. Table 3 has shown that the proposed method has the least correlation of all adjacent pixels (close to zero between pixels adjacent to each other on each pair of horizontal, vertical, and diagonal pixels). It showed the highest level of independence compared to other methods. Table 4 has shown that the proposed method has the highest NPCR and UACI values (NPCR = 99.59%, UACI = 28.47%). It showed that the proposed method is more sensitive to pixel changes than other methods. An entirely random 8-bit grayscale image has an entropy value of 8. This value shows the maximum diffusion of evenly spread pixels with a probability of pixel intensity of 1/256. Table 5 has shown that the RC4 method has the highest entropy value. It showed that the RC4 method had produced an encrypted image that is more random than other methods. The proposed method was the lowest. This is because the proposed method focuses more on the principle of transposition in 3D space. That is, changes occur only in the pixel position in the image without any substitution. The random addition of pixels is only to fulfill the needs of the magic cube pixel slot. From the gray image sample used, 371250 random pixels were added (about 88% of the total pixel sample image). The plain image's entropy value was 7.2547, while the encrypted image has an entropy value of 7.9837. Around 88% of corresponding pixels turned out to only increase the value of entropy by about 10%. PSNR shows how noisy an encrypted image is compared to its plain image. Good encryption should have a reasonably low PSNR.

Conclusion
This study has proposed a magic cube approach method to encrypt an 8-bit grayscale image. This method applies the concept of transposition in 3D space from all pixels of the image placed in a magic cube. Changes only occur in the pixel position when it has returned to the image format without substitution. Applying the proposed method to some selected 8-bit grayscale image samples has shown different performance metrics. The performance metrics comparison (keyspace, correlation, differential, information entropy, and PSNR metrics) against several standard encryption methods have demonstrated that the proposed method was better than the other methods, except for entropy metric (lower than other methods). It was due to the proposed method of not substituting pixel values but transposing their positions. The increase in entropy value that is small enough from the plain image to the encrypted image was due to random pixels' presence to fulfill the pixel slots of the magic cube used. For further studies, modification of the method will be carried out in such a way as to be able to increase its entropy value to very close to 8 and its application to true color images.