Exhaustive key search using pythons Cryptodome and AES repositories. Given plaintext as an input and AES encrypted output and exhaustive key search can bee used to find the key to the AES cipher.
Program description: First the program reads in the given plaintext, cipher and nonce files and stores them as variables. Then a 128 bit binary key with the first bit = 1 and the remaining 127 bits = 0 is created. Then the program runs a loop 2^24 times, giving it enough iterations to find a 128 bit key where 24 bits can be arbitrary numbers. Inside the loop the binary key is converted to bytes, and a new nonce and cipher text are obtained with the given plaintext1 and current key iteration. A decrypted plaintext is created with the given cipher text1 and nonce1, along with the current key iteration. On each iteration of the key, the decrypted plaintext using the current iteration is compared with plaintext1. If the plaintext decryption using the current key matches plaintext1, it is then used to decrypt the second and third ciphertexts and used to compare the decrypted plaintexts to the given plaintexts. If they are a match, the key is outputted in hex along with the decrypted messages. If the encrypted nonce and ciphertext of the current key are not equal, or the plaintext does not match the decryption, the key is converted to binary, then to an integer where it is incremented by one, then returned in bytes key and the loop is repeated with the incremented key.