CryptographyLevel 3★★★☆☆80 pts

Cryptanalysis - Diffie-Hellman with a Small Prime
MissionAn old IoT device performed Diffie-Hellman key exchange with a prime p of only 36 bits. handshake.txt contains p, g, A = g^a mod p, B = g^b mod p and configuration data encrypted with a keystream derived from the shared key. Solve the discrete logarithm, recover the shared key and extract the flag from the configuration data. README.md explains how the keystream is built.
Hints
Hint 1Show
If you find the secret exponent a from A, the shared key is s = B^a mod p. This is the discrete logarithm problem
Hint 2Show
Trying every a takes up to 2^36 steps and will not finish in Python
Hint 3Show
Use baby-step giant-step. With m = ceil(sqrt(p)), store g^j in a dictionary and check whether A*(g^-m)^i is in it