Have a personal or library account? Click to login
Fermat Encoding in S-Box for Secured Encryption Cover
Open Access
|Feb 2025

Full Article

1
Introduction

An S-box, short for “Substitution Box,” is a key factor in modern symmetric-key cryptography. It is a mathematical function that operates on a fixed number of bits, typically 8, 16, or 32 and is used to perform a one-to-one substitution of input values into output values based on a predefined lookup table. In block ciphers, the S-box is extensively used to guarantee confusion property defined by C.E. Shannon for hiding the link between the key and the encoded data [1,2]. S-boxes are vital in cryptographic algorithms like the Advanced Encryption Standard (AES) [3] and the Data Encryption Standard (DES) to familiarize confusion and non-linearity, enhancing the security of encrypted data.

Fermat numbers are a sequence of integers that are defined by the mathematician Pierre de Fermat. It takes the form Fn = 22n + 1, where “n” is a non-negative integer.

In other words, each Fermat number is obtained by raising 2 to the power of 2 raised to another power and then adding 1 to the result. The first few Fermat numbers are: F0=220+1=3,F1=221+1=5,F2=222+1=17,F3=223+1=257,

Fermat numbers have been of interest to mathematicians for centuries, partly due to Fermat’s interest in them and his correspondence with other mathematicians about their properties. However, they are not all prime numbers; in fact, it is known that F4 and beyond are composite (not prime).

2
Literature Review

In 2018, Dragan Lambić [4] proposed a method to acquire random bijective S-boxes based on better one-dimensional discrete chaotic maps. To get over the difficulty of the possibly short length of the orbits of the former discrete-space chaotic map, a special case based on the composition of permutations and sine functions was used. The map was defined over a finite set, which makes it suitable for use on digital computers. In 2020, Eslam W. Afify et al. [5] presented a study of the three types of S-Box by performance analysis and comparative performance study. It showed how an algebraic attack is the most secure lapse of the AES S-box and proposed a modified S-box by enhancing the algebraic properties and Resistance Algebraic Attack (RAA). In 2021, Sarah Mohammed Abdullah and Iman Qays Abduljaleel [6] recommended a reliable scheme for sending speeches. The method had three phases. The first phase is to jumble the speech signal by separating the speech signal into blocks of various sizes of 256 and 128 instances and sorting blocks into matrices in accordant to the length to obtain two matrices then each matrix is divided as par its size into two parts, left and right and rotate only the right side so that the row is a column. The column is a row, while on the other side, a chessboard is applied. The second phase is DNA encryption of the disorganized speech signal by exploitation of a second rule to obtain an enciphered speech signal. The final phase consists of encoding with a Substitution Box that has multiple chaotic maps. In 2021, R. Sherine Jenny, R. Sudhakar, and M. Karthikpriya [7] presented the compact implementation of PRESENT, GIFT and LED, KLEIN, and RECTANGLE S-box. Karnaugh mapping was used to implement the Boolean S-box. In 2021, Ahmad Y. Al-Dweik et al. [8] made a key-dependent dynamic n × n clone S-Box, which has some algebraic properties that give a stronger S-Box to an AES 8 × 8 S-Box. In 2022, Sarita Sanap and Vijayshree More [9] proposed an optimized residue of prime number S-box for AES that gave 13% enhancement with respect to filled slices. The LUTs were maximized by 12.42%. In 2022, A. H. Zahid et al. [10] projected a simple and innovative scheme for the creation of highly nonlinear S-boxes with a cubic modular transformation along with the trigonometric Sine function. A heuristic-based improvement approach, which is random in nature, is proposed to amend the non-linearity of the first S-box. The method uses input factor of integer type in alteration and improvement phases that have the possibility to make a large count of sturdy S-boxes when a small alteration is applied in the parameters’ values. The cipher key is utilized to apply values to the input constant for the creation of dynamic S-boxes. In 2023, Rahul Mishra, Bhupendra Singh, and Radhakrishnan Delhibabu [11] proposed the construction of the AES S-box and explored the possibility of finding S-boxes with similar or better cryptographic properties using a genetic algorithm-based approach applied to one of its elementary. In 2023, Abeer Tariq Maolood et al. [12] created a 4-bit S-box that provides DSAC ideal values equal to zero. the S-box also applied DNA coding to extend each S-box into eight S-boxes, which increases the efficiency of the encrypted images. In 2023 Md. Hasanujjaman, Partha Sarathi Goswami, et al. [13] proposed a new substitution box scheme amalgamating with the concept of Fermat encoding to obtain a secured message-passing technique.

3
Proposed Methodology
Algorithm

Step 1: Take an 8x8 matrix as ‘A’ and an 8X1 matrix as ‘b’

Step 2: Calculate 256 distinct values using the formula 1S(x)=Ax+b

Step 3: Make a S-box with the 256 distinct values obtained.

Encryption of S-Box (Sbox)

Step 1: Take all the values from the S-box {S(0) … S(255)}

Step 2: Perform S(0)=S(0)S(1)S(1)=S(1)S(2)S(2)=S(2)S(3)S(255)=S(255)S(0) where ⊕ is the tensor product [14].

Step 3: Generate Sbox with the 256 values.

Step 4: Obtain the cipher text using Fermat encoding to generate a new encrypted S-box (Sbox) .

Decryption of the S-Box

Step 1: Calculate the values of S-box values forward with the help of Fermat numbers and calculate the values of the S-Box from S(0)′ to S(255)′

Step 2: Make a decrypted S-box with the values.

Step 3: Calculate the values of the S(0) to S(255) with the the help of XOR operation S(255)=S(255)S(0)S(254)=S(254)S(255)S(253)=S(253)S(254)S(0)=S(0)S(1)

Step 4: After this step, make a value of S(0) to S(255) and get the decrypted S-box again.

AES is a symmetric key where a single private key is used for both the encryption and decryption processes. But here, the AES is so designed that it becomes asymmetric, and the encrypted S-box is used as a public key.

The flow diagram of Encryption and Decryption of the S-box is shown in Figure 1 and Figure 2 respectively.

Figure 1.

Encryption of the S-box

Figure 2.

Decryption of the S-box

Flow Diagram:

4
Illustration

The main objective is to create one non-linear S-box [15,16] and then encrypt the S-box as an asymmetric key. To do this, create an 8x8 S-box and then encrypt the S-box. Use the S-box so obtained as a public key in the AES encryption method. The encryption process is illustrated below with an example.

Take any arbitrary values of A and b from the products such that A X b is unique and |A| ≠ 0 for each session. Let, A=[ 1000111111000111111000111111000111111000011111000011111000011111 ],b=[ 11000110 ]

Calculate values of S(0) to S(255) and make the general S-box (0)=[ 1000111111000111111000111111000111111000011111000011111000011111 ][ 00000000 ][ 11000110 ]=[ 11000110 ]S(1)=[ 1000111111000111111000111111000111111000011111000011111000011111 ][ 00000001 ][ 11000110 ]=[ 00110111 ]S(2)=[ 1000111111000111111000111111000111111000011111000011111000011111 ][ 00000010 ][ 11000110 ]=[ 00100101 ] S(254)=[ 1000111111000111111000111111000111111000011111000011111000011111 ][ 11111110 ][ 11000110 ]=[ 1100100 ]S(255)=[ 1000111111000111111000111111000111111000011111000011111000011111 ][ 11111111 ][ 11000110 ]=[ 00111001 ]S(255)=[ 1000111111000111111000111111000111111000011111000011111000011111 ][ 11111111 ][ 11000110 ]=[ 01110011 ]

The binary encrypted S-box so generated is shown in table 1.

Table 1.

S-box Generation

11110001,00010010,11110001,11010101,11110001,
00010010,11110001,01011010,11110001,00010010,
11110001,11010101,11110001,00010010,11110001,
01000101,11110001,00010010,11110001,11010101,
11110001,00010010,11110001,01011010,11110001,
00010010,11110001,11010101,11110001,00010010,
11110001,01111011,11110001,00010010,11110001,
11010101,11110001,00010010,11110001,01011010,
11110001,00010010,11110001,11010101,11110001,
00010010,11110001,01000101,11110001,00010010,
11110001,11010101,11110001,00010010,11110001,
01011010,11110001,00010010,11110001,11010101,
11110001,00010010,11110001,00000111,11110001,
00010010,11110001,11010101,11110001,00010010,
11110001,01011010,11110001,00010010,11110001,
11010101,11110001,00010010,11110001,01000101,
11110001,00010010,11110001,11010101,11110001,
00010010,11110001,01011010,11110001,00010010,
11110001,11010101,11110001,00010010,11110001,
01111011,11110001,00010010,11110001,11010101,
11110001,00010010,11110001,01011010,11110001,
00010010,11110001,11010101,11110001,00010010,
11110001,01000101,11110001,00010010,11110001,
11010101,11110001,00010010,11110001,01011010,
11110001,00010010,11110001,11010101,11110001,
00010010,11110001,11111111,11110001,00010010,
11110001,11010101,11110001,00010010,11110001,
01011010,11110001,00010010,11110001,11010101,
11110001,00010010,11110001,01000101,11110001,
00010010,11110001,11010101,11110001,00010010,
11110001,01011010,11110001,00010010,11110001,
11010101,11110001,00010010,11110001,01111011,
11110001,00010010,11110001,11010101,11110001,
00010010,11110001,01011010,11110001,00010010,
11110001,11010101,11110001,00010010,11110001,
01000101,11110001,00010010,11110001,11010101,
11110001,00010010,11110001,01011010,11110001,
00010010,11110001,11010101,11110001,00010010,
11110001,00000111,11110001,00010010,11110001,
11010101,11110001,00010010,11110001,01011010,
11110001,00010010,11110001,11010101,11110001,
00010010,11110001,01000101,11110001,00010010,
11110001,11010101,11110001,00010010,11110001,
01011010,11110001,00010010,11110001,11010101,
11110001,00010010,11110001,01111011,11110001,
00010010,11110001,11010101,11110001,00010010,
11110001,01011010,11110001,00010010,11110001,
11010101,11110001,00010010,11110001,01000101,
11110001,00010010,11110001,11010101,11110001,
00010010,11110001,01011010,11110001,00010010,
11110001,11010101,11110001,00010010,11110001,
11001000

Now encrypt the S-box a 2nd time using the Fermat encoding process [17]. F0=220+1=3,F1=221+1=5,F2=222+1=17,F3=223+1=257mod256=1,F4=224+1=65537mod256=1,F5=225+1=4294967297mod256=1,F6=226+1=18446744073709551617mod256=1,

Encoding the numbers using Fermat encoding (backward method) is shown in table 2 below.

Table 2.

Fermat encoding using backward method

Index = 0Index = 1Index = 2
241 - 3 = 23818 - 3 = 15241 - 3 = 238
238 - 5 = 23315 - 5 = 10238 - 5 = 233
233 - 17 = 21610 - 17 = 249233 - 17 = 216
216 - 1 = 215249 - 1 = 248216 - 1 = 215
215 - 1 = 214248 - 1 = 247215 - 1 = 214
214 - 1 = 213247 - 1 = 246214 - 1 = 213
213 - 1 = 212246 - 1 = 245213 - 1 = 212
212 - 1 = 211245 - 1 = 244212 - 1 = 211
Index = 3Index = 4Index = 5
213 - 3 = 210241 - 3 = 23818 - 3 = 15
210 - 5 = 205238 - 5 = 23315 - 5 = 10
205 - 17 = 188233 - 17 = 21610 - 17 = 249
188 - 1 = 187216 - 1 = 215249 - 1 = 248
187 - 1 = 186215 - 1 = 214248 - 1 = 247
186 - 1 = 185214 - 1 = 213247 - 1 = 246
185 - 1 = 184213 - 1 = 212246 - 1 = 245
184 - 1 = 183212 - 1 = 211245 - 1 = 244
Index = 6Index =7Index = 8
241 - 3 = 23890 - 3 = 87241 - 3 = 238
238 - 5 = 23387 - 5 = 82238 - 5 = 233
233 - 17 = 21682 - 17 = 65233 - 17 = 216
216 - 1 = 21565 - 1 = 64216 - 1 = 215
215 - 1 = 21464 - 1 = 63215 - 1 = 214
214 - 1 = 21363 - 1 = 62214 - 1 = 213
213 - 1 = 21262 - 1 = 61213 - 1 = 212
212 - 1 = 21161 - 1 = 60212 - 1 = 211
………………………………………………
………………………………………………
Index = 247Index =248Index = 249
90 - 3 = 87241 - 3 = 23818 - 3 = 15
87 - 5 = 82238 - 5 = 23315 - 5 = 10
82 - 17 = 65233 - 17 = 21610 - 17 = 249
65 - 1 = 64216 - 1 = 215249 - 1 = 248
64 - 1 = 63215 - 1 = 214248 - 1 = 247
63 - 1 = 62214 - 1 = 213247 - 1 = 246
62 - 1 = 61213 - 1 = 212246 - 1 = 245
61 - 1 = 60212 - 1 = 211245 - 1 = 244
Index = 250Index = 251Index = 252
241 - 3 = 238213 - 3 = 210241 - 3 = 238
238 - 5 = 233210 - 5 = 205238 - 5 = 233
233 - 17 = 216205 - 17 = 188233 - 17 = 216
216 - 1 = 215188 - 1 = 187216 - 1 = 215
215 - 1 = 214187 - 1 = 186215 - 1 = 214
214 - 1 = 213186 - 1 = 185214 - 1 = 213
213 - 1 = 212185 - 1 = 184213 - 1 = 212
212 - 1 = 211184 - 1 = 183212 - 1 = 211
Index =253Index = 254Index = 255
18 - 3 = 15241 - 3 = 238200 - 3 = 197
15 - 5 = 10238 - 5 = 233197 - 5 = 192
10 - 17 = 249233 - 17 = 216192 - 17 = 175
249 - 1 = 248216 - 1 = 215175 - 1 = 174
248 - 1 = 247215 - 1 = 214174 - 1 = 173
247 - 1 = 246214 - 1 = 213173 - 1 = 172
246 - 1 = 245213 - 1 = 212172 - 1 = 171
245 - 1 = 244212 - 1 = 211171 - 1 = 170

Thus, the encrypted S-box so obtained is shown in table 3.

Table 3.

Encrypted S-Box

21124421118321124421160211
24421118321124421139211244
21118321124421160211244211
18321124421193211244211183
21124421160211244211183211
24421139211244211183211244
21160211244211183211244211
23321124421118321124421160
21124421118321124421139211
24421118321124421160211244
21118321124421193211244211
18321124421160211244211183
21124421139211244211183211
24421160211244211183211244
211225211244211183211244211
6021124421118321124421139
21124421118321124421160211
24421118321124421193211244
21118321124421160211244211
18321124421139211244211183
21124421160211244211183211
244211233211244211183211244
21160211244211183211244211
3921124421118321124421160
21124421118321124421193211
24421118321124421160211244
21118321124421139211244211
18321124421160211244211183
211244211170

Decoding the numbers using the Fermat encoding scheme (forward method) is shown in Table 4 below.

Table 4.

Decryption using Fermat encoding in forward method

Index = 0Index = 1Index = 2
211 + 3 = 214244 + 3 = 247211 + 3 = 214
214 + 5 = 219247 + 5 = 252214 + 5 = 219
219 + 17 = 236252 + 17 = 13219 + 17 = 236
236 + 1 = 23713 + 1 = 14236 + 1 = 237
237 + 1 = 23814 + 1 = 15237 + 1 = 238
238 + 1 = 23915 + 1 = 16238 + 1 = 239
239 + 1 = 24016 + 1 = 17239 + 1 = 240
240 + 1 = 24117 + 1 = 18240 + 1 = 241
Index = 3Index = 4Index = 5
183 + 3 = 186211 + 3 = 214244 + 3 = 247
186 + 5 = 191214 + 5 = 219247 + 5 = 252
191 + 17 = 208219 + 17 = 236252 + 17 = 13
208 + 1 = 209236 + 1 = 23713 + 1 = 14
209 + 1 = 210237 + 1 = 23814 + 1 = 15
210 + 1 = 211238 + 1 = 23915 + 1 = 16
211 + 1 = 212239 + 1 = 24016 + 1 = 17
212 + 1 = 213240 + 1 = 24117 + 1 = 18
Index = 6Index =7Index = 8
211 + 3 = 21460 + 3 = 63211 + 3 = 214
214 + 5 = 21963 + 5 = 68214 + 5 = 219
219 + 17 = 23668 + 17 = 85219 + 17 = 236
236 + 1 = 23785 + 1 = 86236 + 1 = 237
237 + 1 = 23886 + 1 = 87237 + 1 = 238
238 + 1 = 23987 + 1 = 88238 + 1 = 239
239 + 1 = 24088 + 1 = 89239 + 1 = 240
240 + 1 = 24189 + 1 = 90240 + 1 = 241
………………………………………………
………………………………………………
Index = 247Index =248Index = 249
60 + 3 = 63211 + 3 = 214244 + 3 = 247
63 + 5 = 68214 + 5 = 219247 + 5 = 252
68 + 17 = 85219 + 17 = 236252 + 17 = 13
85 + 1 = 86236 + 1 = 23713 + 1 = 14
86 + 1 = 87237 + 1 = 23814 + 1 = 15
87 + 1 = 88238 + 1 = 23915 + 1 = 16
88 + 1 = 89239 + 1 = 24016 + 1 = 17
89 + 1 = 90240 + 1 = 24117 + 1 = 18
Index = 250Index = 251Index = 252
211 + 3 = 214183 + 3 = 186211 + 3 = 214
214 + 5 = 219186 + 5 = 191214 + 5 = 219
219 + 17 = 236191 + 17 = 208219 + 17 = 236
236 + 1 = 237208 + 1 = 209236 + 1 = 237
237 + 1 = 238209 + 1 = 210237 + 1 = 238
238 + 1 = 239210 + 1 = 211238 + 1 = 239
239 + 1 = 240211 + 1 = 212239 + 1 = 240
240 + 1 = 241212 + 1 = 213240 + 1 = 241
Index =253Index = 254Index = 255
244 + 3 = 247211 + 3 = 214170 + 3 = 173
247 + 5 = 252214 + 5 = 219173 + 5 = 178
252 + 17 = 13219 + 17 = 236178 + 17 = 195
13 + 1 = 14236 + 1 = 237195 + 1 = 196
14 + 1 = 15237 + 1 = 238196 + 1 = 197
15 + 1 = 16238 + 1 = 239197 + 1 = 198
16 + 1 = 17239 + 1 = 240198 + 1 = 199
17 + 1 = 18240 + 1 = 241199 + 1 = 200

Thus, the decrypted S-box so obtained is shown in Table 5.

Table 5.

Decrypted S-Box

198553721212402261973
1841709114212710915621740
58203302392531286167181
6814596114131248927234
6320622045119134148101176
658316223122424532209
195501041531391221759476
1891867589168125140158111
5319621439242317224165
84701839814712911242219
201562372814255132117103
15067178160811125023225
204614722215510612013792
1731917820229247621134
481936220722144249826
2351776482163118135149100
3320819451230235244174
95771881051521381230241
227181995436213143126108
15772185171903123825213
21641592021449711513087
166180696617916180133116
102151205604622310251233
249317219079154107121136
2103549192212282467124
14115911018774881692432
16225521972153899146128
11316485711822362915254
4321820057

Decrypt again with the XOR method to find the final S-box that is given in Table 6.

Table 6.

Final Decrypted S-Box

11000110,00110111,00100101,11010100,00000001,
11110000,11100010,00010011,01001001,10111000,
10101010,01011011,10001110,01111111,01101101,
10011100,11011001,00101000,00111010,11001011,
00011110,11101111,11111101,00001100,01010110,
10100111,10110101,01000100,10010001,01100000,
01110010,10000011,11111000,00001001,00011011,
11101010,00111111,11001110,11011100,00101101,
01110111,10000110,10010100,01100101,10110000,
01000001,01010011,10100010,11100111,00010110,
00000100,11110101,00100000,11010001,11000011,
00110010,01101000,10011001,10001011,01111010,
10101111,01011110,01001100,10111101,10111010,
01001011,01011001,10101000,01111101,10001100,
10011110,01101111,00110101,11000100,11010110,
00100111,11110010,00000011,00010001,11100000,
10100101,01010100,01000110,10110111,01100010,
10010011,10000001,01110000,00101010,11011011,
11001001,00111000,11101101,00011100,00001110,
11111111,10000100,01110101,01100111,10010110,
01000011,10110010,10100000,01010001,00001011,
11111010,11101000,00011001,11001100,00111101,
00101111,11011110,10011011,01101010,01111000,
10001001,01011100,10101101,10111111,01001110,
00010100,11100101,11110111,00000110,11010011,
00100010,00110000,11000001,00111110,11001111,
11011101,00101100,11111001,00001000,00011010,
11101011,10110001,01000000,01010010,10100011,
01110110,10000111,10010101,01100100,00100001,
11010000,11000010,00110011,11100110,00010111,
00000101,11110100,10101110,01011111,01001101,
10111100,01101001,10011000,10001010,01111011,
00000000,11110001,11100011,00010010,11000111,
00110110,00100100,11010101,10001111,01111110,
01101100,10011101,01001000,10111001,10101011,
01011010,00011111,11101110,11111100,00001101,
11011000,00101001,00111011,11001010,10010000,
01100001,01110011,10000010,01010111,10100110,
10110100,01000101,01000010,10110011,10100001,
01010000,10000101,01110100,01100110,10010111,
11001101,00111100,00101110,11011111,00001010,
11111011,11101001,00011000,01011101,10101100,
10111110,01001111,10011010,01101011,01111001,
10001000,11010010,00100011,00110001,11000000,
00010101,11100100,11110110,00000111,01111100,
10001101,10011111,01101110,10111011,01001010,
01011000,10101001,11110011,00000010,00010000,
11100001,00110100,11000101,11010111,00100110,
01100011,10010010,10000000,01110001,10100100,
01010101,01000111,10110110,11101100,00011101,
00001111,11111110,00101011,11011010,11001000,
00111001
5
Pseudocode of the Algorithm

 void print_bigger_matrix(int matrix[ROWS_16][COLS_16][BITS], const char *filename) { FILE *file = fopen(filename, “w”);

                      if (file == NULL) {

                      printf(“Error opening file.\n”);

                      return; }

fprintf(file, “[“);

for (int i = 0; i < ROWS_16; i++) {

  for (int j = 0; j < COLS_16; j++) {

    fprintf(file, ““);

    for (int k = 0; k < 8; k++) {

      fprintf(file, “%d”, matrix[i][j][k]); }

    fprintf(file, “, “); }

  fprintf(file, “\n”); }

fprintf(file, “]”);

fclose(file);}

void cartesian_product(int sets[][SET_SIZE], int result[][NUM_SETS]) {

  int index[NUM_SETS] = {0};

  int total_elements = 1;

  for (int i = 0; i < NUM_SETS; ++i) {

    total_elements *= SET_SIZE; }

  for (int i = 0; i < total_elements; ++i) {

    for (int j = 0; j < NUM_SETS; ++j) {

      result[i][j] = sets[j][index[j]];}

    for (int j = NUM_SETS - 1; j >= 0; --j) {

      if (index[j] == SET_SIZE - 1) {

        index[j] = 0;

  } else {

      index[j]++;

      break; } } } }

void convert_to_3D(int matrix[256][8], int result[16][16][8]) {

  for (int i = 0; i < 256; i++) {

    int row = i / 16;

    int col = i % 16;

    for (int j = 0; j < 8; j++) {

      result[row][col][j] = matrix[i][j]; } } }

void xor(int mat1[8][1], int mat2[8][1], int res[8][1]){

  for (int i = 0; i < 8; i++){

    res[i][1] = mat1[i][1] ^ mat2[i][1]; } }

ENCRYPTION

printf(“Enter the numbers separated by spaces:\n”);

for (int i = 0; i < NUM_SETS; ++i) {

    for (int j = 0; j < SET_SIZE; ++j) {

      scanf(“%d”, &sets[i][j]); } }

      cartesian_product(sets, binary_matrix);

      int A[8][8] = {

        {1, 0, 0, 0, 1, 1, 1, 1},

        {1, 1, 0, 0, 0, 1, 1, 1},

        {1, 1, 1, 0, 0, 0, 1, 1},

        {1, 1, 1, 1, 0, 0, 0, 1},

        {1, 1, 1, 1, 1, 0, 0, 0},

        {0, 1, 1, 1, 1, 1, 0, 0},

        {0, 0, 1, 1, 1, 1, 1, 0},

        {0, 0, 0, 1, 1, 1, 1, 1}

      };

      //transpose_row(binary_matrix, b_matrix);

      int B[8][1] = {

        {1},

        {1},

        {0},

        {0},

        {0},

        {1},

        {1},

        {0}

      };

FILE *encryption_debug = fopen(“Encryption_debug.txt”, “w”);

  int decimal = 0;

  for (int index = 0; index <=255; index++){

    fprintf(encryption_debug, “index %d\n”, decimal);

        decimal_to_binary(decimal, x_matrix);

        fprintf(encryption_debug, “X matrix\n”);

    for (int i = 0; i < 8; i++){

      fprintf(encryption_debug, “%d “, x_matrix[i][1]); }

      fprintf(encryption_debug, “\n”);

      matrix_multiply(A, x_matrix, a_x);

      fprintf(encryption_debug, “Ax\n”);

       for (int i = 0; i < 8; i++){

        fprintf(encryption_debug, “%d “, a_x[i][1]); }

      fprintf(encryption_debug, “\n”);

      xor(a_x, B, output_matrix);

       fprintf(encryption_debug, “Ax+B\n”);

  for (int i = 0; i < 8; i++){

    fprintf(encryption_debug, “%d “, output_matrix[i][1]);

    resultant_matrix[index][i] = output_matrix[i][1]; }

      fprintf(encryption_debug, “\n”);

      decimal++; }

  fprintf(encryption_debug, “\n”);

      fprintf(encryption_debug, “Ax+B\n”);

  for (int i = 0; i < 256; i++){

      for (int j = 0; j < 8; j++){

    fprintf(encryption_debug, “%d “, resultant_matrix[i][j]); }

        fprintf(encryption_debug, “\n”); }

  fprintf(encryption_debug, “\nS Box\n”);

  convert_to_3D(resultant_matrix, s_box);

    for (int i = 0; i < 16; i++){

      for (int j = 0; j < 16; j++){

      fprintf(encryption_debug, ““);

          for (int k = 0; k < 8; k++){

  fprintf(encryption_debug, “%d”, s_box[i][j][k]); }

          fprintf(encryption_debug, “,”); }

      fprintf(encryption_debug, “\n”); }

      print_bigger_matrix(s_box, “b_sbox.txt”);

      fclose(encryption_debug);

      fflush(encryption_debug);

      //print_bigger_matrix(s_box, “b_sbox1.txt”);

      for (int i = 0; i < ROWS_16; i++) {

        for (int j = 0; j < COLS_16; j++) {

          for (int k = 0; k < BITS; k++) {

           int s_0[8];

           int xor_val;

           if (i==0 && j==0){

            xor_val = s_box[i][j][k] ^ s_box[i][j+1][k];

            s_0[k] = xor_val;

            s_box_f[i][j][k] = xor_val; }

           else if (i==15 && j==15){

            xor_val = s_0[k] ^ s_box[i][j][k];

            s_box_f[15][15][k] = xor_val; }

           else{

            s_box_f[i][j][k] = s_box[i][j][k] ^ s_box[i][j+1][k]; } } } }

      print_bigger_matrix(s_box_f, “b_enc_sbox.txt”);

      convert_to_decimal(s_box_f, s_box_d);

      printf(“\nS box:\n”);

      print_16x16_matrix(s_box_d);

FILE *fermat_encoding = fopen(“Fermat_encoding.txt”, “w”);

      fprintf(fermat_encoding, “Fermat Encoding: \n”);

      int fe_index = 0;

      for (int i = 0; i < ROWS_16; i++){

       for (int j = 0; j < COLS_16; j++){

        fprintf(fermat_encoding, “Index = %d\n”, fe_index);

        int element = s_box_d[i][j];

        fprintf(fermat_encoding, “\n”);

        for (int k = 0; k < BITS; k++){

         fprintf(fermat_encoding, “%d - %d = “, element, fer-mat_numbers[k]);

          encrypted_val = element - fermat_numbers[k];

          if (encrypted_val<0)

            encrypted_val = 256 + encrypted_val;

          fprintf(fermat_encoding, “%d\n”, encrypted_val);

          element = encrypted_val; }

        fe_index++;

        fprintf(fermat_encoding, “\n”);

        fprintf(fermat_encoding, “\n”);

        s_box_e[i][j] = encrypted_val; } }

      fclose(fermat_encoding);

      fflush(fermat_encoding);

    printf(“\nS box Encrypted:\n”);

      print_16x16_matrix(s_box_e);

FILE *file = fopen(“encrypted_sbox.txt”, “w”);

  if (file == NULL) {

    perror(“Error opening file”);

    return 1; }

  for (int i = 0; i < ROWS_16; ++i) {

    for (int j = 0; j < COLS_16; ++j) {

      fprintf(file, “%d “, s_box_e[i][j]); }

    fprintf(file, “\n”); }

  fclose(file);

printf(“\nS-Box stored in ‘encrypted_sbox.txt’ successfully.\n”);

  printf(“Binary initial sbox stored in ‘b_sbox.txt’\n”);

printf(“Binary encrypted sbox stored in ‘b_enc_sbox.txt’\n”);

      break;

DECRYPTION

printf(“Enter the encrypted s-box filename(decimal): “);

scanf(“%s”, filename);

file = fopen(filename, “r”);

if (file == NULL) {

  perror(“Error opening file”);

  return 1; }

for (int i = 0; i < ROWS_16; ++i) {

  for (int j = 0; j < COLS_16; ++j) {

    if (fscanf(file, “%d”, &s_box_e[i][j]) != 1) {

      fprintf(stderr, “Error reading from file\n”);

      fclose(file);

      return 1; } } }

fclose(file);

printf(“\nEncrypted S-box read from file:\n”);

print_16x16_matrix(s_box_e);

FILE *fermat_decoding = fopen(“Fermat_decoding.txt”, “w”);

  fprintf(fermat_decoding, “Fermat Decoding: \n”);

  int fd_index = 0;

  for (int i = 0; i < ROWS_16; i++){

    for (int j = 0; j < COLS_16; j++){

fprintf(fermat_decoding, “Index = %d\n”, fd_index);

      int element = s_box_e[i][j];

      fprintf(fermat_decoding, “\n”);

      for (int k = 0; k < BITS; k++){

fprintf(fermat_decoding, “%d + %d = “, element, fer-mat_numbers[k]);

  decrypted_val = element + fermat_numbers[k];

    if (decrypted_val>=256)

      decrypted_val = decrypted_val - 256;

fprintf(fermat_encoding, “%d\n”, decrypted_val);

          element = decrypted_val; }

        fd_index++;

        fprintf(fermat_encoding, “\n”);

        fprintf(fermat_encoding, “\n”);

        s_box_d[i][j] = decrypted_val;

        int_to_binary(decrypted_val, s_box_f[i][j]); } }

      fclose(fermat_decoding);

      fflush(fermat_decoding);

      printf(“\nFermat decoded S-box:\n”);

      print_16x16_matrix(s_box_d);

      print_bigger_matrix(s_box, “b_dec_sbox.txt”);

      int s_255[8];

      for (int i = 15; i >= 0; i--) {

        for (int j = 15; j >= 0; j--) {

          for (int k = 0; k < BITS; k++) {

            if (i==15 && j==15){

s_box[i][j][k] = s_box_f[0][0][k] ^ s_box_f[i][j][k];

            s_255[k] = s_box[i][j][k];

            }else{

            s_255[k] = s_box[i][j][k]; } } } }

          printf(“\nDecrypted S-box:\n”);

        convert_to_decimal(s_box, d_s_box);

        print_16x16_matrix(d_s_box);

FILE *decrypted_sbox = fopen(“decrypted_sbox.txt”, “w”);

  if (decrypted_sbox == NULL) {

    perror(“Error opening file”);

    return 1; }

  for (int i = 0; i < ROWS_16; ++i) {

    for (int j = 0; j < COLS_16; ++j) {

  fprintf(decrypted_sbox, “%d “, d_s_box[i][j]); }

fprintf(decrypted_sbox, “\n”); }

      fclose(decrypted_sbox);

      fflush(decrypted_sbox);

      print_bigger_matrix(s_box, “b_dec_sbox.txt”);

printf(“Binary decrypted sbox stored in ‘b_dec_sbox.txt’\n”);

printf(“Decrypted(decimal) sbox stored in ‘decrypted_sbox.txt’\n”);

6
Performance Analysis

The algorithm utilizes the Fermat encoding technique with the cryptographic properties of AES S-Box, and the improved AES S-Box examination results are given in Table 7 below. The number of terms enhances the AES S-Box and improves digital joint addition. Also, the enhanced AES in the S-Box Reverse Sports Joint [18] includes an infinite number of terms from the A-box AES key. It can uphold a dynamic way out of just 9 weaknesses in the AES S-Box digital hinge [19] as well as in the S-Box Affine-Power-Affine (APA) [20] logical component. The associated alteration period has been extended; the enhanced AES S-Box has an optimal implementation of comparative alteration compared to AES S-Box in addition to the S-Box (APA) [2124].

Table 7.

Comparison of S-boxes

Performance indexAES S-BoxAffine-Power-AffineProposed Scheme
Balance criteriabalancebalancebalance
Differential uniformity(F)444
Non-zero linear structurenonenonenone
Number of terms in S-box algebraic expression9255256
Iterative periodless than 88less than 88256
7
Conclusion

In this paper, AES encryption is transformed from symmetric key cryptography to asymmetric key cryptography by encrypting the S-box with the help of the XOR operation and Fermat encoding. Here, the S-box is used as a public key, with which in the AES, there will be two keys: one is the private key and another is the encrypted S-box as a public key.

DOI: https://doi.org/10.2478/ias-2024-0018 | Journal eISSN: 1554-1029 | Journal ISSN: 1554-1010
Language: English
Page range: 266 - 283
Published on: Feb 21, 2025
In partnership with: Paradigm Publishing Services
Publication frequency: 6 issues per year

© 2025 Md. Hasanujjaman, Partha Sarathi Goswami, published by Cerebration Science Publishing Co., Limited
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 License.