A New Block Cipher Algorithm Using Magic Square of Order Five and Galois Field Arithmetic with Dynamic Size Block

This paper describes the development of encryption algorithms using the magic square of order 5 and Multi-level keys with the addition of Matrix keys to increase implementation speed and complexity. This work relied mainly on the magic sum and some equations that were added as an improvement on previous work. Multi-level keys were used for three different message sizes, and an additional key matrix with size 5×5 was used to add more complexity. The proposed work was performed using both GF(P) and GF(28). Results were compared with the MS3, they have been found good, with acceptable speed and high complexity where it was (P)9 × (256)16 in the first algorithm, (P)9 × (256)16 × 3 in the second algorithm, and (P)9 × (256)16 × 3 × (P)25 in the third algorithm, the complexity changed according to the chosen value of N randomness, in addition to speed, complexity, NIST calculations have been performed for texts and histogram calculations for different images were calculated and compared as well. Keywords—cryptography, GF(28), GF(P), magic square, multi-level key


Introduction
The need for modern society to maintain data security has led researchers, mathematicians, and cryptologists to develop encryption algorithms and make them more complex and difficult to access to ensure the protection of information [1]. Interest in magic squares dates back to ancient times, where it was found that BC. Jugglers and magicians used them in their incantations; the Islamists in the past were very interested in magic squares too, as it was previously believed that they contained the nine letters that were revealed to Prophet Adam [2]. Mathematicians and cryptography scholars are also among the first ones interested in magic squares, where many intelligence games have been built based on the idea of magic squares, such as Sudoku [2]. Where the magic square of the third degree was used by assigning some positions to the key and others to the message and multiplying the resulting matrix (from the combination of the key and the message) with a second key matrix equal to the size of the magic square used. As it relied mainly on magic constant [3]. The work was previously developed using the magic square of fifth-degree and different key lengths have been used, namely; 10 and 14 and the key lengths were 15 and 11 respectively. The work has been mainly based on the magic sum [4]. the most important previous works are reviewed through which magic squares were used. In the year 2015, Dawood et. al proposed a new algorithm based on the mathematical foundations of the magic square and the magic cube, where the Diffie-Hellman was used to determine the dimensions of the magic square [5]. Also, a group of researchers developed an algorithm using the magic square, in which two specific magic squares were used and created, then they have used it in cryptography [6]. In 2016, Dawood et al. developed a new method by building the magic cube by folding the magic square, and this method was generalized regardless of the type of magic square used [7]. In 2017, Umar proposed a method based mainly on the 32nd magic square, whereby the duplication of characters was eliminated and the encryption efficiency was improved [8]. In 2019, Al-Hashemy et al. proposed a new algorithm for encrypting images using the magic square, where a random key generation was used and the XOR operation was employed [9]. In the same year, Jabbar et al. proposed a protocol using Magic Square of order 3 and used it in encryption [3]. In 2020, Kareem and Rahma introduced an amendment to the Twofish algorithm in cryptography, whereby 2 keys were used with several rounds, and multi-level keys were used for 4 different message sizes during the work in addition to the use of GF [10]. Later in 2021, Cuevas and Netzer proposed and developed a method based on magic squares and their relationship to cryptography and quantitative information and their relationship to the games [11].

Previously technologies and advantages
Magic squares have many features, so the squares in which the sum of each column is equal to the sum of each row in it is called mini magic square, while if the sum of each row, column, and equal diameter is called normal magic square while if the numbers in the magic square are all prime the square is then called Prime Magic Square [12,16].
To take advantage of the properties of the magic squares, the switch has been made from unspecified numbers to specific numbers, depending on Prime Number(P), and all Galois field (GF) will depend on P [12]. The need for the devices currently in use prompted the change from relying on GF(P) to the use of polynomial numbers GF(2 8 ), as each Galois field will depend on the irreducible polynomial in its mathematical that used addition and multiplication [13]. Just as for each specific GF(2 Number ) there is a certain number of irreducible polynomials that can be used within that range, there are only 30 irreducible polynomials that can be used within GF (2 8 ) [14,17]. Before retrieving the original text, the work will be changed to a linear equation system and noting that the number of equations is equal to the number of unknowns to be solved. before solving the work by Gaussian elimination or anyway is chosen requires arranging the equations in such a way that the main diagonal does not contain the value zero, and the final result of the Gaussian elimination method will restore the plain text [15,18]. Cryptography is a science that uses mainly mathematics to encode and decode data by using algorithms with the help of a key [14].
Multi-level keys is a system that consists of more than one layer of keys, in such a way that the information is stored in a small database and the required key sequence is chosen from it [15]. In this proposed paper, we will use magic square, GF with both types, Additional message length, Multi-level keys, and Extra Key, in order, as will be seen later.

3
The proposed cryptography technique Since increasing the number of equations in the magic square leads to an increase in the speed of the encryption, a method for increasing the speed is therefore proposed.

3.1
Add more equations to the system proposed Four additional equations were added to the proposed system as shown in Figure 1 below.  (Figure 1 a & b), so the total of equations will be equal to 16. Therefore, therewill be 16 locations for the message corresponding to 16 equations (out of 25 for MS 5) and the remaining 9 locations for a key. Which would like to refer to that there are no keys locations or key values determined by the specified algorithm, but rather they are flexible to the user.
3.1.1 Inserting the message and key. By default the following locations for the key were considered to be selected: From Figure 2, where the shown positions represent the selected key locations (9 locations) and the remaining sites will represent the message positions in about 16 locations, so the total is 25 locations (for MS 5), as shown in Figure 3  The recipient will solve the 16 equations, where there will be 16 unknown corresponding to the 16 equations, and the remaining 9 are known to both sides (the key).
Before solving equations, it is required to arrange the equations in such a way that the principal diameter is not equal to zero. The equations will be solved according to the rules of the specified field to obtain the final solution of the text or image message (see sec. 3 Para. 4) in this paper. The proposed work was developed to increase the strength and difficulty of breaking it so that the polynomial number was used instead of integers in both the message and the key value.

The suggested algorithms.
There is neither a fixed nor a specific algorithm, and the following suggested method represents an improvement for GF 5 both encryption and decryption respectively. Step2: The remaining places will accommodate the message.
Step3: The result of Steps 1 and 2 will be that MS5 will be filled with 16 locations for the message and 9 positions for the key, and this result will represent the matrix A (as seen in Figure 3), and in this step will find the results for all summation in (1). The final output for this step will be representing the ciphertext. Step3: The equations obtained from Step 2 will be arranged so that the main diagonal does not contain the zero value. Step4: The sixteen equations will be solved based on the finite domain rules used for GF(P), as seen in this paper (sec. 3 Para. 4). Through this step, the original text or image will be restored.

End.
A development to the algorithm 1 suggested above was done to suit the devices currently in use and to increase the strength and the difficulty of breaking it, so the GF(P) was replaced by GF(2 8 ) because of the devices at present use 8 bits in their work.

Use message lengths together
Using the different longest messages together will increase the power of the proposed algorithm. In this proposed algorithm #2 will use Multi-level keys.
Therefore, the numbers 0, 1, and 2 are randomly chosen. If the selected number was equal zero, then it will be encoded and decoded using MS 5 with the message length = 10. Whereas if the selected number = one, the encryption algorithm of MS 5 will be used with message length = 14. Otherwise, encryption & decryption will be done by MS 5 with message length = 16. (Algorithm 1 in this paper). The Suggested algorithm 2 will be illustrated in Figure 4 below:

Use an extra key
The present proposed algorithm represents Algorithm # 3 in this paper. Thus, increasing the number of keys used will increase the strength of the encryption.

The process of multiply the key in MS 5.
A square will be used as a 2D array whose size is equal to the size of MS 5, and the values inside will be randomly selected to act as a key between the two ends, as shown in Figure 5 below.  Figure 4).
Step3: the result of Step2 will multiplyw with the key Matrix cell by cell (see Figure 5).
Step4: the result of the step3 will be treated like Step3 in Alg.1 Encryption in this paper.
The result of step4 (the sums) will represent the ciphertext. End.

Algorithm 3-b: The Suggested Symmetric cipher algorithm For MS 5 (Decryption)
Input: Ciphertext, keys position, keys values, keys Matrix, Multi-level keys used. Output: Original text or Image.

Begin:
Step1: Depending on the value of the key N to find out the length of the message used (see Figure 4).
Step2: Same as Step1 in Alg.1 Decryption in this paper.
Step3: The remaining positions in MS 5 will filled with the message and here the length of the message will depend on the value of n. Step4: Same as Step3+Step4 in Alg.1 Decryption in this paper.
Step5: The result from Step4 will find the inverse for each number with the key Matrix to find the original text or Image.

End.
In this algorithm 3#, development was also made, where the prime number was replaced by an irreducible polynomial to increase efficiency, power, reduce speed, and make the algorithm more compatible with devices.

Evaluation
Cryptography is a method used to maintain the confidentiality, integrity, and Authentication of data when it is sent between two parties that have a connection, the method is done by combining the sent data with a key (the key is known only between the two recipient parties) and sending it to the receiving party, on the opposite side, the recipient extracts the key from the encrypted text received to obtain the original text, this is done using mathematical methods. On the other hand, the number of attempts that the third party is supposed to try to access the sent data is called brute force attack. In this paper, MS5 is used with message length = 16, the use of multi-level keys for three lengths of the message, and the process of multiplying the key with MS5. This is all as an improvement on MS3 and MS4 by continuously increasing the complexity of the proposed algorithms in an ascending sequence to reach to state of difficult-to-access data. In this part, will discuss and compare (complexity, speed, histogram calculation of images, and NIST calculations) of the three proposed algorithms for GF with its two types, and compare the results for the proposed algorithms together, and also compare the results with MS3. The results in this section were obtained using a laptop with the following specifications: Processor : Intel(R) Core(TM) i5-4310M CPU @ 2.70GHz (4 CPUs), ~2.7GHz. Installed Memory (RAM) : 8 GB, System Type : 64-bit Operating System.

Security complexity for brute force attack
The complexity of the brute force attack is represented by the complexity of the key only for each proposed algorithm and for MS3. For MS3 using GF(P), the calculation of brute force attack power = 3, represented by the length of the key used and the prime number used = P while using GF(2 8 ) the key length is also 3 and 2 8 = 256. While for the first algorithm proposed using GF(P), it is calculated by the remaining number of subtracting the message length for MS5 = 9 (25-16), and the prime number was used will be referred to by P as shown in (2), as if used irreducible polynomial in GF (2 8 ), also it is calculated with 9 (the remaining number From subtracting the length of the message) and 2 8 = 256, see (3). 9 (2) B4 = (256) 9 (3) As for the second algorithm proposed, the difference from the first algorithm will be the multi-level keys used, which equals 3 multiplied by the results of the first algorithm (Depends on the length of the message(, for each of the two types of GF, see (4) and (5).
As for the third proposed algorithm for GF(P), the result of the second algorithm will be multiplied by the key matrix used, which is equal to the size of MS5 and the prime number = P, see (6), and for GF(2 8 ) will also the result for algorithm #2 proposed multiplied by the matrix Key and multiplied by the number of irreducible polynomials allowed used for GF (2 8 ), as shown in (7).

Security complexity analysis
Here will calculate the data complexity for each algorithm separately, For MS3, data complexity would be equal to ASCII code which is equal to 256 raised to the power of the message length would be 6 (size of general MS3 minus key length = 3. As for the first algorithm suggested, the data complexity will be the ASCII code number raised the message length used, which equals 16. As for the data complexity of the second algorithm suggested, it will have three states according to the message length used 10, 14, or 16, and the ASCII code itself is equal to 256, so the complexity in the data will be either (256) 10 , (256) 14 or (256) 16 (depending on the length of the message). As for the data complexity of the third algorithm suggested, it will be quite similar to the second algorithm. Thus, overall complexity = keys complexity (brute force attack complexity multiplied by data complexity), each algorithm will be calculated separately in equations (8)-(21), and the results are presented and compared with MS3 as in Figure 7. C1 = ( p) 9 × (256) 16 (8)

Time for encryption and decryption processes
Another measure that was calculated for the proposed algorithms is the time of implementation of the encryption and decryption where experiments were conducted on the text of different characters' length and images of different sizes, times were found for GF of both types, and Tables 1 & 2

The relationship of execution time to complexity
It is another measure that takes into account the increase in the implementation time with the increase in complexity and noting that the increase in the time of implementation was small compared to the increase in complexity or not, as detailed in Figure 10.

NIST test and stats
The tests are conducted for the ciphertext produced from the proposed algorithms and for each type of GF, where randomness, complexity, and repetition of characters are calculated according to the NIST tests (National Institute of Standards and Technology), as the results are shown in the Tables 3-5.

Histogram for images
It is another measure of the efficiency of the proposed algorithms in terms of ciphered images. Measurements were made for different types of images and each type of GF. This type of measurement is knowing the color distribution in the formed cipher and compared with the original image as shown below in Figures 11 & 12.  Fig. 11. Apply all the suggested methods to Image1 and find a histogram of the resulting images When comparing the previous results, we note that encryption using MS5 is much better in terms of complexity, speed, and randomness of the encrypted text than MS3.
As for the proposed algorithms, the first algorithm gives very good results and it is considered a successful development where the increase in the equations leads to an increase in speed in implementations. As for the second algorithm, the complexity is three times that of the first algorithm and the speed is almost equal. Whereas, if the choice is made on the number of fewer equations, it will correspondingly increase in complexity, else if the choice is on the number of more equations, it will be an increase in the speed of implementation. While the third algorithm has very high complexity compared to the previous algorithms. But it takes some time to implement, especially in pictures because it uses GF(2 8 ), Nevertheless, the increase in complexity remains very large against the increase in time and is considered a very excellent suggestion due to the large increase in complexity. The added complexity of an additional key adds much more complexity than the one present in MS5 because the entire additive matrix represents a key. It is preferable to encrypt text with the third algorithm, as it has very high complexity. As for images, it is preferable to encrypt them using the second algorithm, as it has good complexity and appropriate speed, and if more complexity is required, the third algorithm is the most appropriate.

Conclusions
The proposed algorithms provided an example of the fact that using more equations results in increasing the speed of execution. When using multi-level keys, it gives high complexity and maintains the same speed approximately. When using a high value of P in GF(P) it results in giving higher complexity with very little overtime. 8-bit encryption was used because the devices rely on 8-bit coding, and this thing is clear when dealing with images. When multiplying MS5 by a key matrix, it provides a very high complexity, and the complexity increases with increasing the value of P. On the other hand, it requires additional time in implementation, but the percentage increase of complexity is higher than the percentage increase of time. When using GF(2 8 ) the complexity will be multiplied by 30, because there are 30 possibilities for selecting the irreducible polynomial number in the third algorithm (multiplication operation).