diff --git a/python/foobar/three/hash_someone_else.py b/python/foobar/three/hash_someone_else.py new file mode 100644 index 0000000..a6a3725 --- /dev/null +++ b/python/foobar/three/hash_someone_else.py @@ -0,0 +1,19 @@ +def step(digest,prev_m): + k = 0 + while True: + rem = ((digest ^ prev_m) + k * 256) % 129 + if rem == 0: + return ((digest ^ prev_m) + k * 256) / 129 + else: + k = k + 1 + +def answer(digest): + prev = 0 + message = [] + for index, num in enumerate(digest): + if index == 0: + message.append(step(num,0)) + else: + message.append(step(num,message[-1])) + + return message diff --git a/python/utils/connect.py b/python/utils/connect.py new file mode 100644 index 0000000..1ef1a96 --- /dev/null +++ b/python/utils/connect.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +import socket +import sys + +def get_header(sock): + try: + data = sock.recv(4096, socket.MSG_DONTWAIT) # 0x40 : O_NONBLOCK + #sys.stdout.write(data) + print(data.decode("utf-8"), end="") + except socket.error as msg: + # Nothing left + pass + +try: + sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) +except socket.error as msg: + print(msg) + sys.exit(1) + +try: + sock = socket.create_connection((sys.argv[1], sys.argv[2]),60) +except socket.error as msg: + print(msg) + sock.close() + sys.exit(1) + +if sock is None: + print('Unable to connect') + sys.exit(2) + +#sock.setblocking(0) +sock.shutdown(socket.SHUT_WR) +print("Connected to %s:%s" % (sys.argv[1],sys.argv[2])) +get_header(sock) +sock.close()