Rating: 5.0
# Crypto: EAV-Secure Diffie–Hellman?
## Source code review
>## key_exchange.py
```python
from Crypto.Util.number import bytes_to_long, long_to_bytes
# I love making homespun cryptographic schemes!
def diffie_hellman():
f = open("flag.txt", "r")
flag = f.read()
a = bytes_to_long(flag.encode('utf-8'))
#print(a)
#print(long_to_bytes(a))
p = 320907854534300658334827579113595683489
g = 3
A = pow(g,a,p) #236498462734017891143727364481546318401
if __name__ == "__main__":
diffie_hellman()
# EAV-Secure? What's that?
```
To solve this challenge we need to find exponent `x` value. The problem is well known as `The Discrete Logarithm Problem`. It is used in diffie hellman key exchange more about it [here](https://ir0nstone.gitbook.io/crypto/dhke/overview#the-discrete-logarithm-problem)
## Getting the flag
Because given numbers are relatively small we can try to calculate x value. I found [online calculator](https://www.alpertron.com.ar/DILOG.HTM) that worked.
The only step left is to write a Python script that will find the final value of x and decode it into our flag
```python
from Crypto.Util.number import bytes_to_long, long_to_bytes
for i in range(1,1000000000):
a = 67514057458967447420279566091192598301
b = 320907854534300658334827579113595683488
flag = long_to_bytes(a+(b*i))
if b"wsc{" in flag:
print(flag)
break
```
## FLAG: wsc{l0g_j4m_4tt4ck}