Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example code to communicate with "Machine Learning Binaries" technical challenge.
import requests
import logging
import base64
import time
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
class Server(object):
url = ''
log = logging.getLogger(__name__)
def __init__(self):
self.session = requests.session()
self.binary = None
self.hash = None
self.wins = 0
self.targets = []
def _request(self, route, method='get', data=None):
while True:
if method == 'get':
r = self.session.get(self.url + route)
r = + route, data=data)
if r.status_code == 429:
raise Exception('Rate Limit Exception')
if r.status_code == 500:
raise Exception('Unknown Server Exception')
return r.json()
except Exception as e:
self.log.error(e)'Waiting 60 seconds before next request')
def get(self):
r = self._request("/challenge")
self.targets = r.get('target', [])
self.binary = base64.b64decode(r.get('binary', ''))
return r
def post(self, target):
r = self._request("/solve", method="post", data={"target": target})
self.wins = r.get('correct', 0)
self.hash = r.get('hash', self.hash)
self.ans = r.get('target', 'unknown')
return r
if __name__ == "__main__":
import random
# create the server object
s = Server()
for _ in range(10):
# query the /challenge endpoint
# choose a random target and /solve
target = random.choice(s.targets)"Guess:[{: >9}] Answer:[{: >9}] Wins:[{: >3}]".format(target, s.ans, s.wins))
# 500 consecutive correct answers are required to win
# very very unlikely with current code
if s.hash:"You win! {}".format(s.hash))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.