Skip to content

Instantly share code, notes, and snippets.

@tomdaley92
Last active December 31, 2017 07:23
Show Gist options
  • Save tomdaley92/5128bc4d38b88044086f2d4530393679 to your computer and use it in GitHub Desktop.
Save tomdaley92/5128bc4d38b88044086f2d4530393679 to your computer and use it in GitHub Desktop.
Ethos programming challenge <http://dev.getethos.com>
#!/usr/bin/env python3
'''
Thomas Daley
October 16, 2017
This code contains the solution for the programming
challenge hosted at dev.getethos.com
The first step is to find the instructions which can be
done in various ways. You can simply download the page
with nc or any web browser. Even better, you can open
chrome dev tools and you'll notice right away that the css
for the "instructions" element is commented out. Try
uncommenting it.
Sum of all "cool numbers" in [1, 1000000]: 70601040511
Code: ilovejavascript
TCP port 6175 is found to open after scanning ports 1000-9999
with Nmap. When connecting to that port it will immediately
close after sending back:
You found me! The code is: portscanningftw
'''
import requests
from collections import deque
BASE_URL = 'http://dev.getethos.com'
SECRET = 'portscanningftw'
# Fill in info to subscribe
email = '???'
name = '???'
want_job = False
source = '???'
def main():
x = x_cool_sum()
#x = 70601040511
code = get_code(x)
#code = 'ilovejavascript'
print('X-COOL-SUM: ' + str(x))
print('CODE: ' + code)
login(code)
print(subscribe(email, name, want_job, source, SECRET))
def get_digits(x):
left = x
digits = deque()
while left > 9:
right = left % 10
left = left // 10
digits.appendleft(right)
digits.appendleft(left)
return digits
def is_cool(x):
if x < 1:
return False
new_x = x
while new_x != 1:
digits = get_digits(new_x)
new_x = 0
while digits:
new_x += digits.popleft()**2
if new_x == 4:
return False
return True
def x_cool_sum():
n = 0
for i in range(1, 1000001):
if is_cool(i):
n += i
return n
def get_code(x_cool_sum):
headers = { 'X-COOL-SUM' : str(x_cool_sum) }
code = ""
for i in range(1,101):
r = requests.post(url=BASE_URL + '/code' + str(i), headers=headers)
if r.status_code != 404:
code += r.text
return code
def login(code):
headers = { 'Cookie' : 'authorized=true' }
data = { 'code' : code }
r = requests.post(url=BASE_URL, headers=headers, data=data)
if r.status_code == 200:
print('Logged in!')
with open("cracked.html", "wb") as f:
f.write(r.content)
else:
print(r.text)
return r.text
def subscribe(email, name, want_job, source, code):
headers = { 'Cookie' : 'authorized=true' }
data = ({ 'email' : email,
'name' : name,
'wantJob': 'Yes' if want_job else 'No',
'source' : source,
'code' : code })
r = requests.post(url=BASE_URL + '/subscribe', headers=headers, data=data)
if r.status_code == 200:
print('Subscribed!')
with open("subscribed.html", "wb") as f:
f.write(r.content)
else:
print(r.text)
return r.text
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment