# Rohan Sangani
# 11/3/2025
# Executes a Diffie-Hellman Key Exchange via an Elliptic Curve.
# Adapted from https://www.cs.ucf.edu/~dmarino/ucf/cis3362/progs/EllipticCurveDH.java

from EllipticCurve import EllipticCurve
from Point import Point

def main():
    # Define an elliptic curve and a generator
    curve = EllipticCurve(23, 1, 1)
    gen = Point(curve, 19, 18)

    # For every possible pair of private keys
    for n_alice in range(1, 31):
        for n_bob in range(1, 31):
            alice_send = gen * n_alice
            bob_send = gen * n_bob

            # Uncomment to see what gets sent
            # print(f"Alice sends to Bob: {alice_send}")
            # print(f"Bob sends to Alice: {bob_send}")

            alice_gets = bob_send * n_alice
            bob_gets = alice_send * n_bob

            # Uncomment to see exchanged key (they should be the same, but if they aren't, you'll see it in the if statement)
            # print(f"Alice gets: {alice_gets}")
            # print(f"Bob gets: {bob_gets}")

            # If all goes well and nothing is uncommented, it should print nothing (like javac or diff)
            if alice_gets != bob_gets:
                print(
                    f"ERROR {n_alice} {n_bob}\n"
                    f"Alice sends to Bob: {alice_send}\n"
                    f"Bob sends to Alice: {bob_send}\n"
                    f"Alice gets: {alice_gets}\n"
                    f"Bob gets: {bob_gets}"
                )

if __name__ == '__main__':
    main()