def test_ElGamal(num_bit, message): print("\n------------------------------------------------------") # Generate random prime numbers p = BlumBlumShub.generate_prime(num_bit) # Test generate_keypair which returns public key ( g, p, h) and the private key (g, p, x) public, private = ElGamal.generate_keypair(p) print("\n------------------------------------------------------") encrypted_msg = ElGamal.encrypt(public, message) print("\n------------------------------------------------------") decrypted_msg = ElGamal.decrypt(private, encrypted_msg) print("\n------------------------------------------------------") eve_decrypted_msg = ElGamal.eve(public, encrypted_msg) return decrypted_msg, eve_decrypted_msg
# If encryption algorithm is RSA if type_encryption == "1": result = [int(x.strip()) for x in public.split(',')] public_key = (result[0], result[1]) # Eavesdrop with factorization and decrypt the message with RSA Algorithm RSA.factorization(public_key, encrypted_msg) # If encryption algorithm is El-Gamal elif type_encryption == "2": result = [int(x.strip()) for x in public.split(',')] # Eavesdrop with baby-step giant-step and decrypt the message with El-Gamal Algorithm ElGamal.eve((result[0], result[1], result[2]), encrypted_msg) # Otherwise, function 5 - Choose other encryption algorithm elif function == "5": break # Otherwise, nope else: print() print("Oh, that's not proper choose...") elif type_encryption == "3": running = False # Otherwise, nope else: print() print("Oh, that's not proper choose...")