#!/usr/bin/env python3

import base64
import hashlib
import hmac
import http.client

key = "4v2676craytxdzh9kx6mbslfi66709hlx4q96cymi4v8y2liqygt3kqnzwuroqq7".encode()


def digest(password):
    return hmac.HMAC(key, base64.b64encode((password*3).encode()), hashlib.sha256).digest()


target = digest("Freedom")

n = 0
while True:
    d = digest(str(n))
    if d[0:2] == target[0:2]:
        break
    n += 1

conn = http.client.HTTPConnection("challenges.ringzer0team.com:10187")
conn.request("GET", f"/index.php?x={n}")
resp = conn.getresponse()
html = resp.read().decode()
print(html)
conn.close()
