diff --git a/scripts/client.c b/communication/client.c similarity index 96% rename from scripts/client.c rename to communication/client.c index 02d6ed0e3b1dd3be136ae57a976685545ad0a9fa..84efafe016c9e78126b643e79002d7b5397949ca 100644 --- a/scripts/client.c +++ b/communication/client.c @@ -1,157 +1,157 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <wolfssl/ssl.h> -#include <wolfssl/wolfcrypt/error-crypt.h> -#include <wolfssl/openssl/err.h> -#include <unistd.h> -#include <arpa/inet.h> - -#define CERT_FILE "../certificates/ca-cert.pem" -#define SERVER_IP "192.168.178.51" // Die IP-Adresse des Servers -#define PORT 5000 -#define BUFFER_SIZE 1024 - -void initWolfSSL() { - wolfSSL_Init(); // Initialize WolfSSL library -} - -void cleanupWolfSSL() { - wolfSSL_Cleanup(); // Cleanup WolfSSL library -} - -int createClientSocket(const char *server_ip, int port) { - int client_fd; - struct sockaddr_in server_addr; - - if ((client_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { - perror("Socket creation failed"); - exit(EXIT_FAILURE); - } - - memset(&server_addr, 0, sizeof(server_addr)); - server_addr.sin_family = AF_INET; - server_addr.sin_port = htons(port); - if (inet_pton(AF_INET, server_ip, &server_addr.sin_addr) <= 0) { - perror("Invalid server IP address"); - close(client_fd); - exit(EXIT_FAILURE); - } - - if (connect(client_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) { - perror("Connection failed"); - close(client_fd); - exit(EXIT_FAILURE); - } - - return client_fd; -} - -int main() { - // Verschlüsselungsalgorithmus auswählen (AES, RSA, etc.) - int choice; - printf("Wählen Sie den Verschlüsselungsalgorithmus:\n"); - printf("1. TLSv1.2 mit AES\n"); - printf("2. TLSv1.3\n"); - printf("Geben Sie Ihre Wahl ein (1 oder 2): "); - scanf("%d", &choice); - - // Initialize WolfSSL - initWolfSSL(); - - // Konfiguration des Verschlüsselungsalgorithmus - const WOLFSSL_METHOD *method; // Korrekte Methode für WolfSSL - if (choice == 1) { - method = wolfTLSv1_2_client_method(); // TLSv1.2 - } else { - method = wolfTLSv1_3_client_method(); // TLSv1.3 - } - - // Load CA certificate - WOLFSSL_CTX *ctx = wolfSSL_CTX_new(method); - if (ctx == NULL) { - printf("Failed to create SSL context\n"); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - if (wolfSSL_CTX_load_verify_locations(ctx, CERT_FILE, NULL) != SSL_SUCCESS) { - printf("Failed to load CA certificate\n"); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - // Create client socket - int client_fd = createClientSocket(SERVER_IP, PORT); - - // Create SSL object - WOLFSSL *ssl = wolfSSL_new(ctx); - if (ssl == NULL) { - printf("Failed to create SSL object\n"); - close(client_fd); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - // Associate socket with SSL object - if (wolfSSL_set_fd(ssl, client_fd) != SSL_SUCCESS) { - printf("Failed to associate socket with SSL object\n"); - wolfSSL_free(ssl); - close(client_fd); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - // Perform TLS handshake - if (wolfSSL_connect(ssl) != SSL_SUCCESS) { - printf("SSL handshake failed\n"); - wolfSSL_free(ssl); - close(client_fd); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - printf("Connected to the server!\n"); - - // Open the file to send - const char *file_path = "../testData/test.txt"; - FILE *file = fopen(file_path, "rb"); - if (file == NULL) { - perror("Failed to open file"); - wolfSSL_free(ssl); - close(client_fd); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - // Send file in chunks - char buffer[BUFFER_SIZE]; - size_t bytes_read; - while ((bytes_read = fread(buffer, 1, sizeof(buffer), file)) > 0) { - if (wolfSSL_write(ssl, buffer, bytes_read) != bytes_read) { - printf("Error sending file\n"); - fclose(file); - wolfSSL_free(ssl); - close(client_fd); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - } - - printf("File '%s' successfully sent to the server.\n", file_path); - - // Clean up - fclose(file); - wolfSSL_free(ssl); - close(client_fd); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - - return 0; -} +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <wolfssl/ssl.h> +#include <wolfssl/wolfcrypt/error-crypt.h> +#include <wolfssl/openssl/err.h> +#include <unistd.h> +#include <arpa/inet.h> + +#define CERT_FILE "../certificates/ca-cert.pem" +#define SERVER_IP "192.168.178.51" // Die IP-Adresse des Servers +#define PORT 5000 +#define BUFFER_SIZE 1024 + +void initWolfSSL() { + wolfSSL_Init(); // Initialize WolfSSL library +} + +void cleanupWolfSSL() { + wolfSSL_Cleanup(); // Cleanup WolfSSL library +} + +int createClientSocket(const char *server_ip, int port) { + int client_fd; + struct sockaddr_in server_addr; + + if ((client_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { + perror("Socket creation failed"); + exit(EXIT_FAILURE); + } + + memset(&server_addr, 0, sizeof(server_addr)); + server_addr.sin_family = AF_INET; + server_addr.sin_port = htons(port); + if (inet_pton(AF_INET, server_ip, &server_addr.sin_addr) <= 0) { + perror("Invalid server IP address"); + close(client_fd); + exit(EXIT_FAILURE); + } + + if (connect(client_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) { + perror("Connection failed"); + close(client_fd); + exit(EXIT_FAILURE); + } + + return client_fd; +} + +int main() { + // Verschlüsselungsalgorithmus auswählen (AES, RSA, etc.) + int choice; + printf("Wählen Sie den Verschlüsselungsalgorithmus:\n"); + printf("1. TLSv1.2 mit AES\n"); + printf("2. TLSv1.3\n"); + printf("Geben Sie Ihre Wahl ein (1 oder 2): "); + scanf("%d", &choice); + + // Initialize WolfSSL + initWolfSSL(); + + // Konfiguration des Verschlüsselungsalgorithmus + const WOLFSSL_METHOD *method; // Korrekte Methode für WolfSSL + if (choice == 1) { + method = wolfTLSv1_2_client_method(); // TLSv1.2 + } else { + method = wolfTLSv1_3_client_method(); // TLSv1.3 + } + + // Load CA certificate + WOLFSSL_CTX *ctx = wolfSSL_CTX_new(method); + if (ctx == NULL) { + printf("Failed to create SSL context\n"); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + if (wolfSSL_CTX_load_verify_locations(ctx, CERT_FILE, NULL) != SSL_SUCCESS) { + printf("Failed to load CA certificate\n"); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + // Create client socket + int client_fd = createClientSocket(SERVER_IP, PORT); + + // Create SSL object + WOLFSSL *ssl = wolfSSL_new(ctx); + if (ssl == NULL) { + printf("Failed to create SSL object\n"); + close(client_fd); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + // Associate socket with SSL object + if (wolfSSL_set_fd(ssl, client_fd) != SSL_SUCCESS) { + printf("Failed to associate socket with SSL object\n"); + wolfSSL_free(ssl); + close(client_fd); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + // Perform TLS handshake + if (wolfSSL_connect(ssl) != SSL_SUCCESS) { + printf("SSL handshake failed\n"); + wolfSSL_free(ssl); + close(client_fd); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + printf("Connected to the server!\n"); + + // Open the file to send + const char *file_path = "../testData/test.txt"; + FILE *file = fopen(file_path, "rb"); + if (file == NULL) { + perror("Failed to open file"); + wolfSSL_free(ssl); + close(client_fd); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + // Send file in chunks + char buffer[BUFFER_SIZE]; + size_t bytes_read; + while ((bytes_read = fread(buffer, 1, sizeof(buffer), file)) > 0) { + if (wolfSSL_write(ssl, buffer, bytes_read) != bytes_read) { + printf("Error sending file\n"); + fclose(file); + wolfSSL_free(ssl); + close(client_fd); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + } + + printf("File '%s' successfully sent to the server.\n", file_path); + + // Clean up + fclose(file); + wolfSSL_free(ssl); + close(client_fd); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + + return 0; +} diff --git a/scripts/client.py b/communication/client.py similarity index 100% rename from scripts/client.py rename to communication/client.py diff --git a/scripts/server.c b/communication/server.c similarity index 96% rename from scripts/server.c rename to communication/server.c index 6906d30babb47c2e7d6162dd179e6765c4074041..71135641c9b036ff16f61fc3c8fd884d51fac1e9 100644 --- a/scripts/server.c +++ b/communication/server.c @@ -1,179 +1,179 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <wolfssl/ssl.h> -#include <wolfssl/wolfcrypt/error-crypt.h> -#include <wolfssl/openssl/err.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <unistd.h> - -#define CERT_FILE "../certificates/server-cert.pem" -#define KEY_FILE "../certificates/server-key.pem" -#define PORT 5000 -#define BUFFER_SIZE 1024 - -void initWolfSSL() { - wolfSSL_Init(); // Initialize WolfSSL library -} - -void cleanupWolfSSL() { - wolfSSL_Cleanup(); // Cleanup WolfSSL library -} - -int createServerSocket(int port) { - int server_fd; - struct sockaddr_in server_addr; - - if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { - perror("Socket creation failed"); - exit(EXIT_FAILURE); - } - - memset(&server_addr, 0, sizeof(server_addr)); - server_addr.sin_family = AF_INET; - server_addr.sin_addr.s_addr = INADDR_ANY; - server_addr.sin_port = htons(port); - - if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) { - perror("Binding failed"); - close(server_fd); - exit(EXIT_FAILURE); - } - - if (listen(server_fd, 1) == -1) { - perror("Listening failed"); - close(server_fd); - exit(EXIT_FAILURE); - } - - printf("Server is listening on port %d...\n", port); - return server_fd; -} - -int main() { - // Verschlüsselungsalgorithmus auswählen (AES, RSA, etc.) - int choice; - printf("Wählen Sie den Verschlüsselungsalgorithmus:\n"); - printf("1. TLSv1.2 mit AES\n"); - printf("2. TLSv1.3\n"); - printf("Geben Sie Ihre Wahl ein (1 oder 2): "); - scanf("%d", &choice); - - // Initialize WolfSSL - initWolfSSL(); - - // Create server socket - int server_fd = createServerSocket(PORT); - - // Konfiguration des Verschlüsselungsalgorithmus - const WOLFSSL_METHOD *method; // Korrekte Methode für WolfSSL - if (choice == 1) { - method = wolfTLSv1_2_client_method(); // TLSv1.2 - } else { - method = wolfTLSv1_3_client_method(); // TLSv1.3 - } - - // SSL-Kontext erstellen - WOLFSSL_CTX *ctx = wolfSSL_CTX_new(method); - if (ctx == NULL) { - printf("Failed to create SSL context\n"); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - if (wolfSSL_CTX_use_certificate_file(ctx, CERT_FILE, SSL_FILETYPE_PEM) != SSL_SUCCESS) { - printf("Failed to load certificate\n"); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - if (wolfSSL_CTX_use_PrivateKey_file(ctx, KEY_FILE, SSL_FILETYPE_PEM) != SSL_SUCCESS) { - printf("Failed to load private key\n"); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - // Accept client connection - int client_fd = accept(server_fd, NULL, NULL); - if (client_fd == -1) { - perror("Accept failed"); - close(server_fd); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - // Create SSL object - WOLFSSL *ssl = wolfSSL_new(ctx); - if (ssl == NULL) { - printf("Failed to create SSL object\n"); - close(client_fd); - close(server_fd); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - // Associate socket with SSL object - if (wolfSSL_set_fd(ssl, client_fd) != SSL_SUCCESS) { - printf("Failed to associate socket with SSL object\n"); - wolfSSL_free(ssl); - close(client_fd); - close(server_fd); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - // Perform TLS handshake - if (wolfSSL_accept(ssl) != SSL_SUCCESS) { - printf("SSL handshake failed\n"); - wolfSSL_free(ssl); - close(client_fd); - close(server_fd); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - printf("TLS handshake completed successfully\n"); - - // Receive file data - FILE *file = fopen("received_file.txt", "wb"); - if (file == NULL) { - perror("File open failed"); - wolfSSL_free(ssl); - close(client_fd); - close(server_fd); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - exit(EXIT_FAILURE); - } - - char buffer[BUFFER_SIZE]; - int bytes_received; - while ((bytes_received = wolfSSL_read(ssl, buffer, sizeof(buffer))) > 0) { - fwrite(buffer, 1, bytes_received, file); - } - - if (bytes_received < 0) { - printf("Error receiving file\n"); - } else { - printf("File successfully received and saved as 'received_file.txt'\n"); - } - - fclose(file); - - // Clean up - wolfSSL_free(ssl); - close(client_fd); - close(server_fd); - wolfSSL_CTX_free(ctx); - cleanupWolfSSL(); - - return 0; -} +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <wolfssl/ssl.h> +#include <wolfssl/wolfcrypt/error-crypt.h> +#include <wolfssl/openssl/err.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <unistd.h> + +#define CERT_FILE "../certificates/server-cert.pem" +#define KEY_FILE "../certificates/server-key.pem" +#define PORT 5000 +#define BUFFER_SIZE 1024 + +void initWolfSSL() { + wolfSSL_Init(); // Initialize WolfSSL library +} + +void cleanupWolfSSL() { + wolfSSL_Cleanup(); // Cleanup WolfSSL library +} + +int createServerSocket(int port) { + int server_fd; + struct sockaddr_in server_addr; + + if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { + perror("Socket creation failed"); + exit(EXIT_FAILURE); + } + + memset(&server_addr, 0, sizeof(server_addr)); + server_addr.sin_family = AF_INET; + server_addr.sin_addr.s_addr = INADDR_ANY; + server_addr.sin_port = htons(port); + + if (bind(server_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) { + perror("Binding failed"); + close(server_fd); + exit(EXIT_FAILURE); + } + + if (listen(server_fd, 1) == -1) { + perror("Listening failed"); + close(server_fd); + exit(EXIT_FAILURE); + } + + printf("Server is listening on port %d...\n", port); + return server_fd; +} + +int main() { + // Verschlüsselungsalgorithmus auswählen (AES, RSA, etc.) + int choice; + printf("Wählen Sie den Verschlüsselungsalgorithmus:\n"); + printf("1. TLSv1.2 mit AES\n"); + printf("2. TLSv1.3\n"); + printf("Geben Sie Ihre Wahl ein (1 oder 2): "); + scanf("%d", &choice); + + // Initialize WolfSSL + initWolfSSL(); + + // Create server socket + int server_fd = createServerSocket(PORT); + + // Konfiguration des Verschlüsselungsalgorithmus + const WOLFSSL_METHOD *method; // Korrekte Methode für WolfSSL + if (choice == 1) { + method = wolfTLSv1_2_client_method(); // TLSv1.2 + } else { + method = wolfTLSv1_3_client_method(); // TLSv1.3 + } + + // SSL-Kontext erstellen + WOLFSSL_CTX *ctx = wolfSSL_CTX_new(method); + if (ctx == NULL) { + printf("Failed to create SSL context\n"); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + if (wolfSSL_CTX_use_certificate_file(ctx, CERT_FILE, SSL_FILETYPE_PEM) != SSL_SUCCESS) { + printf("Failed to load certificate\n"); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + if (wolfSSL_CTX_use_PrivateKey_file(ctx, KEY_FILE, SSL_FILETYPE_PEM) != SSL_SUCCESS) { + printf("Failed to load private key\n"); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + // Accept client connection + int client_fd = accept(server_fd, NULL, NULL); + if (client_fd == -1) { + perror("Accept failed"); + close(server_fd); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + // Create SSL object + WOLFSSL *ssl = wolfSSL_new(ctx); + if (ssl == NULL) { + printf("Failed to create SSL object\n"); + close(client_fd); + close(server_fd); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + // Associate socket with SSL object + if (wolfSSL_set_fd(ssl, client_fd) != SSL_SUCCESS) { + printf("Failed to associate socket with SSL object\n"); + wolfSSL_free(ssl); + close(client_fd); + close(server_fd); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + // Perform TLS handshake + if (wolfSSL_accept(ssl) != SSL_SUCCESS) { + printf("SSL handshake failed\n"); + wolfSSL_free(ssl); + close(client_fd); + close(server_fd); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + printf("TLS handshake completed successfully\n"); + + // Receive file data + FILE *file = fopen("received_file.txt", "wb"); + if (file == NULL) { + perror("File open failed"); + wolfSSL_free(ssl); + close(client_fd); + close(server_fd); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + exit(EXIT_FAILURE); + } + + char buffer[BUFFER_SIZE]; + int bytes_received; + while ((bytes_received = wolfSSL_read(ssl, buffer, sizeof(buffer))) > 0) { + fwrite(buffer, 1, bytes_received, file); + } + + if (bytes_received < 0) { + printf("Error receiving file\n"); + } else { + printf("File successfully received and saved as 'received_file.txt'\n"); + } + + fclose(file); + + // Clean up + wolfSSL_free(ssl); + close(client_fd); + close(server_fd); + wolfSSL_CTX_free(ctx); + cleanupWolfSSL(); + + return 0; +} diff --git a/scripts/server.py b/communication/server.py similarity index 100% rename from scripts/server.py rename to communication/server.py diff --git a/decryption/3des.py b/decryption/3des.py new file mode 100644 index 0000000000000000000000000000000000000000..443b73d350f113a68e76382bbd87256e54dd5803 --- /dev/null +++ b/decryption/3des.py @@ -0,0 +1,32 @@ +from Crypto.Cipher import DES3 +from itertools import product + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_3des.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 + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = DES3.new(key, DES3.MODE_ECB) + plaintext = cipher.decrypt(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_3des(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/blowfish.py b/decryption/blowfish.py new file mode 100644 index 0000000000000000000000000000000000000000..0600f9f9567d7bc7d8b844cbbdb5eca741c794d2 --- /dev/null +++ b/decryption/blowfish.py @@ -0,0 +1,32 @@ +from Crypto.Cipher import Blowfish +from itertools import product + +# 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 + 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 + 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_blowfish(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/camellia.py b/decryption/camellia.py new file mode 100644 index 0000000000000000000000000000000000000000..ae8ae0ee84eb51cf8941cff88fd32f32efcfbb20 --- /dev/null +++ b/decryption/camellia.py @@ -0,0 +1,33 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..efb6e80144e32395bc9970792e45a5c8fa4b9c58 --- /dev/null +++ b/decryption/rc4.py @@ -0,0 +1,33 @@ +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