![](http://webcf.waybackmachine.org/web/20221216024043im_/https://habrastorage.org/getpro/habr/avatars/37c/bfa/c90/37cbfac90f1af44ff5700274a9b74ecf.jpg)
How to exchange a secret key over an insecure network (EC-Diffie-Hellman algorithm)
![](https://webcf.waybackmachine.org/web/20221216024043im_/https://habrastorage.org/getpro/habr/upload_files/679/bfa/5c9/679bfa5c9d9e0047ab073a54c927fc54.png)
Let’s say you want to send an encrypted message to your friend in order to avoid it being intercepted and read by a third party. You generate a random secret key and encrypt the message with it. Let’s say you use AES. But how do you let your friend know the key to decrypt it?
In this article, we will explore how the Elliptic-Curve Diffie-Hellman algorithm works under the hood. The article includes the implementation of this algorithm from scratch, written in Python.