## 4 Research Methodology
### Dynamic AES Key Replacement Mechanism
The rationale behind choosing these parameters is rooted in their ability to meet the security and efficiency requirements of IoT devices. The prime modulus \(P=2,147,483,647\) is a 31-bit prime number that provides a robust foundation for the discrete logarithm problem, which is the basis of the D-H protocol. While traditional implementations often use larger primes to achieve higher security levels, the 31-bit prime is more suitable for IoT applications where computational efficiency is critical. This size of \(P\) ensures that brute-force attacks remain computationally infeasible, even when attempted on adversarial hardware. Similarly, the generator \(G=37\) was selected as a small, fixed integer to optimize the modular exponentiation process. Using a smaller generator reduces the computational burden on microcontrollers, allowing for faster key calculations while maintaining adequate randomness and security. Additionally, this choice ensures a uniform distribution of the generated keys across the finite field defined by the modulus \(P\), which is essential for preserving cryptographic strength. The combination of \(G=37\) and \(P=2,147,483,647\) provides an effective trade-off between security and performance, making it particularly well-suited for lightweight microcontrollers. In IoT scenarios, the time and energy constraints of adversaries, coupled with the real-time operational demands of IoT devices, further mitigate the risks of brute-force and similar attacks. These parameters are not only computationally efficient but also sufficiently secure for practical deployment in real-world IoT applications, such as access control systems and sensor networks. To implement this lightweight D-H key exchange, the public keys are computed by each party, using their private keys as \(PK_{A}=G^{a}\bmod P\) for the IoT device and \(PK_{B}=G^{b}\bmod P\) for the server. Once the public keys are exchanged, the shared symmetric key is derived as \(\text{SK}=PK_{B}{}^{a}\bmod P=PK_{A}{}^{b}\bmod P\). This ensures that both parties compute the same shared key due to the commutative property of modular exponentia  
Figure 8: D-H key exchange. tion. The detailed step-by-step process of this key exchange is outlined in Table 4, which illustrates the sequence of operations required to establish the shared symmetric key. This lightweight implementation of the D-H key exchange ensures secure key distribution, even for devices with limited processing power, by balancing computational efficiency and cryptographic strength. Through the careful selection of parameters and optimization of the microcontroller's workload, this approach provides a highly efficient solution for IoT environments, where resource constraints are a critical consideration. It enables secure cryptographic key exchanges without compromising the performance of resource-constrained devices, such as the Arduino Uno. The proposed method not only meets the security demands of modern IoT applications but also demonstrates excellent adaptability to the constraints of real-world deployments, where both energy consumption and processing capabilities are limited. This lightweight D-H mechanism is ideal for scalable IoT networks that require robust security without sacrificing performance.