I am very new to python and for my assignment i have been asked to “Encrypt a public key using the DES/AES algorithm. The secret DES/AES key (Ks) used is from step 2.” Step 2 asks me to negotiate a shared key (Ks) using Diffie-Hellman protocol with p = 23 and g =17. How is this supposed to be done? I’ve looked through countless youtube videos and I have no idea how the shared key can be used in the code. PLS HELP…
What have you tried so far? It’s easier to help if you show us what code you’ve tried.
(public_key, private_key) = rsa.newkeys(2048) p = 23 g = 17 alice_key = 8 a = (g**alice_key) % p conn = socket.socket() conn.connect((socket.gethostname(), 12345)) bob_key = conn.recv(1024).decode("utf-8") conn.send(str(a).encode('utf-8')) final = (int(bob_key)**a) % p print("shared key: " + str(final)) key = token_bytes(final)
the shared key was 16.
i have no idea how accurate the usage of the following code (taken from DES Encryption In Python - YouTub) is but it is the only one i’ve seen which allowed me to use the shared key in any capacity as
key = token_bytes(final). i am getting alot of errors tho. but i reiterate i’m very new to python.
cipher = DES.new(key, DES.MODE_EAX) nonce = cipher.nonce ciphertext, tag = cipher.encrypt_and_digest(public_key.encode('ascii'))
Does your assignment require the use of the socket stuff? I don’t think I understand the parameters of your assignment.