diff --git a/communication/client.c b/communicationScripts/client.c similarity index 100% rename from communication/client.c rename to communicationScripts/client.c diff --git a/communication/client.py b/communicationScripts/client.py similarity index 100% rename from communication/client.py rename to communicationScripts/client.py diff --git a/communication/server.c b/communicationScripts/server.c similarity index 100% rename from communication/server.c rename to communicationScripts/server.c diff --git a/communication/server.py b/communicationScripts/server.py similarity index 100% rename from communication/server.py rename to communicationScripts/server.py diff --git a/decryption/camellia.py b/decryption/camellia.py deleted file mode 100644 index ae8ae0ee84eb51cf8941cff88fd32f32efcfbb20..0000000000000000000000000000000000000000 --- a/decryption/camellia.py +++ /dev/null @@ -1,33 +0,0 @@ -from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes -import itertools - -# Verschlüsselten Datenstrom laden -with open('encrypted_file_camellia.bin', 'rb') as f: - ciphertext = f.read() - -start_time = time.time() # Startzeit -# Brute-Force-Funktion für Camellia -def brute_force_camellia(ciphertext): - key_space = (bytes([k]) for k in range(2**8)) # 8-Bit Schlüsselraum zur Demo - target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt - for key in key_space: - try: - cipher = Cipher(algorithms.Camellia(key.ljust(16, b'\0')), modes.ECB()) - decryptor = cipher.decryptor() - plaintext = decryptor.update(ciphertext) - if target_pattern in plaintext: # Überprüfung des entschlüsselten Inhalts - print(f"Schlüssel gefunden: {key}") - print(f"Entschlüsselter Inhalt: {plaintext}") - return plaintext - except Exception as e: - continue - -end_time = time.time() -plaintext = brute_force_camellia(ciphertext) -if plaintext: - print("Datei erfolgreich entschlüsselt!") -else: - print("Kein gültiger Schlüssel gefunden.") - -duration = end_time - start_time -print(f"Dauer des Angriffs: {duration:.2f} Sekunden") \ No newline at end of file diff --git a/decryption/rc4.py b/decryption/rc4.py deleted file mode 100644 index efb6e80144e32395bc9970792e45a5c8fa4b9c58..0000000000000000000000000000000000000000 --- a/decryption/rc4.py +++ /dev/null @@ -1,33 +0,0 @@ -from cryptography.hazmat.primitives.ciphers import Cipher, algorithms -import itertools - -# Verschlüsselten Datenstrom laden -with open('encrypted_file_rc4.bin', 'rb') as f: - ciphertext = f.read() - -start_time = time.time() # Startzeit -# Brute-Force-Funktion für RC4 -def brute_force_rc4(ciphertext): - key_space = (bytes([k]) for k in range(2**8)) # 8-Bit Schlüsselraum zur Demo - target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt - for key in key_space: - try: - cipher = Cipher(algorithms.ARC4(key), mode=None) - decryptor = cipher.decryptor() - plaintext = decryptor.update(ciphertext) - if target_pattern in plaintext: # Überprüfung des entschlüsselten Inhalts - print(f"Schlüssel gefunden: {key}") - print(f"Entschlüsselter Inhalt: {plaintext}") - return plaintext - except Exception as e: - continue - -end_time = time.time() -plaintext = brute_force_rc4(ciphertext) -if plaintext: - print("Datei erfolgreich entschlüsselt!") -else: - print("Kein gültiger Schlüssel gefunden.") - -duration = end_time - start_time -print(f"Dauer des Angriffs: {duration:.2f} Sekunden") \ No newline at end of file diff --git a/decryptionScripts/aes-128bit.py b/decryptionScripts/aes-128bit.py new file mode 100644 index 0000000000000000000000000000000000000000..5b0761836a2cdb00fdb3ff5a29060f0402ec354a --- /dev/null +++ b/decryptionScripts/aes-128bit.py @@ -0,0 +1,34 @@ +from Crypto.Cipher import AES +from itertools import product +import time + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_aes.bin', 'rb') as f: + ciphertext = f.read() + +start_time = time.time() # Startzeit + +# Brute-Force-Funktion für AES mit 128-Bit Schlüssel +def brute_force_aes_128bit(ciphertext): + key_space = (bytes([k]) for k in range(256)) # Beispiel für 128-Bit Schlüsselraum + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = AES.new(key, AES.MODE_ECB) + plaintext = cipher.decrypt(ciphertext) + if target_pattern in plaintext: + print(f"Schlüssel gefunden: {key}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") + return plaintext + except Exception as e: + continue + +end_time = time.time() +plaintext = brute_force_aes_128bit(ciphertext) +if plaintext: + print("Datei erfolgreich entschlüsselt!") +else: + print("Kein gültiger Schlüssel gefunden.") + +duration = end_time - start_time +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryptionScripts/aes-256bit.py b/decryptionScripts/aes-256bit.py new file mode 100644 index 0000000000000000000000000000000000000000..ee4ba0889ce0b3b4b80addd1e261a992180cfed6 --- /dev/null +++ b/decryptionScripts/aes-256bit.py @@ -0,0 +1,34 @@ +from Crypto.Cipher import AES +from itertools import product +import time + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_aes.bin', 'rb') as f: + ciphertext = f.read() + +start_time = time.time() # Startzeit + +# Brute-Force-Funktion für AES mit 256-Bit Schlüssel +def brute_force_aes_256bit(ciphertext): + key_space = (b''.join(k) for k in product(b'abc123', repeat=32)) # Beispiel für 256-Bit Schlüsselraum + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = AES.new(key, AES.MODE_ECB) + plaintext = cipher.decrypt(ciphertext) + if target_pattern in plaintext: + print(f"Schlüssel gefunden: {key}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") + return plaintext + except Exception as e: + continue + +end_time = time.time() +plaintext = brute_force_aes_256bit(ciphertext) +if plaintext: + print("Datei erfolgreich entschlüsselt!") +else: + print("Kein gültiger Schlüssel gefunden.") + +duration = end_time - start_time +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryption/blowfish.py b/decryptionScripts/blowfish-128bit.py similarity index 67% rename from decryption/blowfish.py rename to decryptionScripts/blowfish-128bit.py index 0600f9f9567d7bc7d8b844cbbdb5eca741c794d2..7a8af87b26e5c17d2fb9e0545e9896613830ac5f 100644 --- a/decryption/blowfish.py +++ b/decryptionScripts/blowfish-128bit.py @@ -1,32 +1,34 @@ from Crypto.Cipher import Blowfish from itertools import product +import time # Verschlüsselten Datenstrom laden with open('encrypted_file_blowfish.bin', 'rb') as f: ciphertext = f.read() start_time = time.time() # Startzeit -# Brute-Force-Funktion für Blowfish -def brute_force_blowfish(ciphertext): - key_space = (b''.join(k) for k in product(b'abc123', repeat=4)) # Demo: Schlüsselraum für 32-Bit + +# Brute-Force-Funktion für Blowfish mit 128-Bit Schlüssel +def brute_force_blowfish_128bit(ciphertext): + key_space = (b''.join(k) for k in product(b'abc123', repeat=16)) # Beispiel für 128-Bit Schlüsselraum target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt for key in key_space: try: cipher = Blowfish.new(key, Blowfish.MODE_ECB) plaintext = cipher.decrypt(ciphertext) - if target_pattern in plaintext: # Überprüfung des entschlüsselten Inhalts + if target_pattern in plaintext: print(f"Schlüssel gefunden: {key}") - print(f"Entschlüsselter Inhalt: {plaintext}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") return plaintext except Exception as e: continue end_time = time.time() -plaintext = brute_force_blowfish(ciphertext) +plaintext = brute_force_blowfish_128bit(ciphertext) if plaintext: print("Datei erfolgreich entschlüsselt!") else: print("Kein gültiger Schlüssel gefunden.") duration = end_time - start_time -print(f"Dauer des Angriffs: {duration:.2f} Sekunden") \ No newline at end of file +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryptionScripts/blowfish-64bit.py b/decryptionScripts/blowfish-64bit.py new file mode 100644 index 0000000000000000000000000000000000000000..4f0531c2490f6252dc5274fe91af0b86e8bfe538 --- /dev/null +++ b/decryptionScripts/blowfish-64bit.py @@ -0,0 +1,34 @@ +from Crypto.Cipher import Blowfish +from itertools import product +import time + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_blowfish.bin', 'rb') as f: + ciphertext = f.read() + +start_time = time.time() # Startzeit + +# Brute-Force-Funktion für Blowfish mit 64-Bit Schlüssel +def brute_force_blowfish_64bit(ciphertext): + key_space = (bytes([k]) for k in range(256)) # Beispiel für 64-Bit Schlüsselraum + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = Blowfish.new(key, Blowfish.MODE_ECB) + plaintext = cipher.decrypt(ciphertext) + if target_pattern in plaintext: + print(f"Schlüssel gefunden: {key}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") + return plaintext + except Exception as e: + continue + +end_time = time.time() +plaintext = brute_force_blowfish_64bit(ciphertext) +if plaintext: + print("Datei erfolgreich entschlüsselt!") +else: + print("Kein gültiger Schlüssel gefunden.") + +duration = end_time - start_time +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryption/3des.py b/decryptionScripts/rc4-64bit.py similarity index 58% rename from decryption/3des.py rename to decryptionScripts/rc4-64bit.py index 443b73d350f113a68e76382bbd87256e54dd5803..b9749766b3fc1b8219cdc0333611490ea9c1b659 100644 --- a/decryption/3des.py +++ b/decryptionScripts/rc4-64bit.py @@ -1,32 +1,34 @@ -from Crypto.Cipher import DES3 +from Crypto.Cipher import ARC4 from itertools import product +import time # Verschlüsselten Datenstrom laden -with open('encrypted_file_3des.bin', 'rb') as f: +with open('encrypted_file_rc4.bin', 'rb') as f: ciphertext = f.read() start_time = time.time() # Startzeit -# Brute-Force-Funktion für 3DES -def brute_force_3des(ciphertext): - key_space = (b''.join(k) for k in product(b'abc123', repeat=8)) # Demo: Schlüsselraum für 3DES + +# Brute-Force-Funktion für RC4 mit 64-Bit Schlüssel +def brute_force_rc4_64bit(ciphertext): + key_space = (b''.join(k) for k in product(b'abc123', repeat=8)) # Beispiel für 64-Bit Schlüsselraum target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt for key in key_space: try: - cipher = DES3.new(key, DES3.MODE_ECB) + cipher = ARC4.new(key) plaintext = cipher.decrypt(ciphertext) - if target_pattern in plaintext: # Überprüfung des entschlüsselten Inhalts + if target_pattern in plaintext: print(f"Schlüssel gefunden: {key}") - print(f"Entschlüsselter Inhalt: {plaintext}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") return plaintext except Exception as e: continue end_time = time.time() -plaintext = brute_force_3des(ciphertext) +plaintext = brute_force_rc4_64bit(ciphertext) if plaintext: print("Datei erfolgreich entschlüsselt!") else: print("Kein gültiger Schlüssel gefunden.") duration = end_time - start_time -print(f"Dauer des Angriffs: {duration:.2f} Sekunden") \ No newline at end of file +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryptionScripts/rc4-8bit.py b/decryptionScripts/rc4-8bit.py new file mode 100644 index 0000000000000000000000000000000000000000..cb2fc4c6b3393938bab51367adf5484350dc351c --- /dev/null +++ b/decryptionScripts/rc4-8bit.py @@ -0,0 +1,34 @@ +from Crypto.Cipher import ARC4 +from itertools import product +import time + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_rc4.bin', 'rb') as f: + ciphertext = f.read() + +start_time = time.time() # Startzeit + +# Brute-Force-Funktion für RC4 mit 8-Bit Schlüssel +def brute_force_rc4_8bit(ciphertext): + key_space = (bytes([k]) for k in range(256)) # 8-Bit Schlüsselraum (alle möglichen 1-Byte-Schlüssel) + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = ARC4.new(key) + plaintext = cipher.decrypt(ciphertext) + if target_pattern in plaintext: + print(f"Schlüssel gefunden: {key}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") + return plaintext + except Exception as e: + continue + +end_time = time.time() +plaintext = brute_force_rc4_8bit(ciphertext) +if plaintext: + print("Datei erfolgreich entschlüsselt!") +else: + print("Kein gültiger Schlüssel gefunden.") + +duration = end_time - start_time +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryptionScripts/twofish-128bit.py b/decryptionScripts/twofish-128bit.py new file mode 100644 index 0000000000000000000000000000000000000000..f03c70cfac88d74d1b320d907f7042c00f0817a3 --- /dev/null +++ b/decryptionScripts/twofish-128bit.py @@ -0,0 +1,34 @@ +from twofish import Twofish +from itertools import product +import time + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_twofish.bin', 'rb') as f: + ciphertext = f.read() + +start_time = time.time() # Startzeit + +# Brute-Force-Funktion für Twofish mit 128-Bit Schlüssel +def brute_force_twofish_128bit(ciphertext): + key_space = (bytes([k]) for k in range(256)) # Beispiel für 128-Bit Schlüsselraum + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = Twofish.new(key, Twofish.MODE_ECB) + plaintext = cipher.decrypt(ciphertext) + if target_pattern in plaintext: + print(f"Schlüssel gefunden: {key}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") + return plaintext + except Exception as e: + continue + +end_time = time.time() +plaintext = brute_force_twofish_128bit(ciphertext) +if plaintext: + print("Datei erfolgreich entschlüsselt!") +else: + print("Kein gültiger Schlüssel gefunden.") + +duration = end_time - start_time +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryptionScripts/twofish-256bit.py b/decryptionScripts/twofish-256bit.py new file mode 100644 index 0000000000000000000000000000000000000000..3ecfd30750d2b779df57f47593123474a5c1e133 --- /dev/null +++ b/decryptionScripts/twofish-256bit.py @@ -0,0 +1,34 @@ +from twofish import Twofish +from itertools import product +import time + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_twofish.bin', 'rb') as f: + ciphertext = f.read() + +start_time = time.time() # Startzeit + +# Brute-Force-Funktion für Twofish mit 256-Bit Schlüssel +def brute_force_twofish_256bit(ciphertext): + key_space = (b''.join(k) for k in product(b'abc123', repeat=32)) # Beispiel für 256-Bit Schlüsselraum + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = Twofish.new(key, Twofish.MODE_ECB) + plaintext = cipher.decrypt(ciphertext) + if target_pattern in plaintext: + print(f"Schlüssel gefunden: {key}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") + return plaintext + except Exception as e: + continue + +end_time = time.time() +plaintext = brute_force_twofish_256bit(ciphertext) +if plaintext: + print("Datei erfolgreich entschlüsselt!") +else: + print("Kein gültiger Schlüssel gefunden.") + +duration = end_time - start_time +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/readme.md b/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..6271c02a0b25439f9b272f33b2fb78ed069e9191 --- /dev/null +++ b/readme.md @@ -0,0 +1,19 @@ +### Folder Structure + +- **Certificates** + - This folder contains the communication certificates that have been created. These certificates are generated by the `certificateCreation.sh` script located in the **Setup** folder + +- **CommunicationScripts** + - This folder includes the server and client scripts that build the end-to-end communication between the two Raspberry Pis + +- **EncryptedData** + - This folder stores the encrypted data collected during the communication between the two devices + +- **DecryptionScripts** + - This folder contains scripts designed to decrypt the collected binary data. These scripts process the encrypted data and inform if the enrcyption was successful or not + +- **Setup** + - This folder includes essential setup scripts and configuration files to prepare the environment: + - `certificateCreation.sh`: A script that generates all necessary certificates for secure communication + - `decryption.sh`: A script that installs the required libraries and dependencies needed to execute the decryption scripts + - `wolfsslInstallation`: A script to install and configure the `wolfSSL` library, which is used for secure communication between the devices diff --git a/setup/certificate-creation.sh b/setup/certificateCreation.sh similarity index 100% rename from setup/certificate-creation.sh rename to setup/certificateCreation.sh diff --git a/setup/compilation_client.sh b/setup/compilation_client.sh deleted file mode 100644 index 26d9c1c59297581c67b3e23b470797a88ec451a5..0000000000000000000000000000000000000000 --- a/setup/compilation_client.sh +++ /dev/null @@ -1,5 +0,0 @@ -# Compile client script -gcc -o client_program ../scripts/client.c -lwolfssl - -# start client -./client_program \ No newline at end of file diff --git a/setup/compilation_server.sh b/setup/compilation_server.sh deleted file mode 100644 index c96d21047f500e51cf797bf799a2a8b753ce153a..0000000000000000000000000000000000000000 --- a/setup/compilation_server.sh +++ /dev/null @@ -1,5 +0,0 @@ -# Compile server script -gcc -o server_program ../scripts/server.c -lwolfssl - -# start server -./server_program \ No newline at end of file diff --git a/setup/decryption.sh b/setup/decryption.sh new file mode 100644 index 0000000000000000000000000000000000000000..5834a9abaf13d9fbb355575f69efc8e8d4d7066a --- /dev/null +++ b/setup/decryption.sh @@ -0,0 +1,3 @@ +# Install dependencies for decryption scripts +pip install pycryptodome +pip install twofish \ No newline at end of file diff --git a/setup/wolfssl-installaltion.sh b/setup/wolfssInstallaltion.sh similarity index 100% rename from setup/wolfssl-installaltion.sh rename to setup/wolfssInstallaltion.sh