Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created May 18, 2015 00:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/60eda1db5c7d8b852840 to your computer and use it in GitHub Desktop.
Save anonymous/60eda1db5c7d8b852840 to your computer and use it in GitHub Desktop.
import socket
import random
host = "blackbox_ced7f267475a0299446fa86c26d77161.quals.shallweplayaga.me"
port = 18324
inputs = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ "
s = socket.socket()
s.connect((host, port))
print s.recv(2048)
print s.recv(2048)
test = "ABab"
# Box 1
s.sendall(test+"\n")
rec = s.recv(2048)
resp = rec[rec.index("[")+1:rec.index("\t")-1]
shift = inputs.index(resp[0])
shift -= inputs.index(test[0])
resp = rec[rec.index("Expected"):]
ans = resp[resp.index("[")+1:-2]
out = ""
for l in ans:
key = (inputs.index(l)-shift) % len(inputs)
out += inputs[key]
print out
s.sendall(out+"\n")
print s.recv(2048)
print s.recv(2048)
# Box 2
test = "ABAAAAA"
s.sendall(test+"\n")
rec = s.recv(2048)
print rec
resp = rec[rec.index("Expected"):]
ans = resp[resp.index("[")+1:-2]
print repr(ans)
out = ""
shift = 0
for l in ans:
key = inputs.index(l)-shift
shift += inputs.index(l)
shift = shift % len(inputs)
out += inputs[key]
print out
s.sendall(out+"\n")
print s.recv(2048)
print s.recv(2048)
test = "ABCDA"
s.sendall(test+"\n")
rec = s.recv(2048)
print rec
out = ""
resp = rec[rec.index("[")+1:rec.index("\t")-1]
shift = inputs.index(resp[0])
shift -= inputs.index(test[0])
print shift, resp[0], test[0]
resp = rec[rec.index("Expected"):]
ans = resp[resp.index("[")+1:-2]
print repr(ans)
for l in ans:
key = (inputs.index(l)-shift) % len(inputs)
out += inputs[key]
print out
out = out[::-1]
s.sendall(out+"\n")
print s.recv(2048)
print s.recv(2048)
s.sendall("A"*40+"\n")
rec = s.recv(2048)
key = rec[rec.index("[")+1:rec.index("\t")-1]
resp = rec[rec.index("Expected"):]
ans = resp[resp.index("[")+1:-2]
out = ""
for i in xrange(len(ans)):
shift = inputs.index(key[i])
out += inputs[(inputs.index(ans[i]) - shift)%len(inputs)]
print out
s.sendall(out + "\n")
print s.recv(2048)
print s.recv(2048)
#box 5
s.sendall("AAAA\n")
rec = s.recv(2048)
key = rec[rec.index("[")+1:rec.index("\t")-1]
resp = rec[rec.index("Expected"):]
ans = resp[resp.index("[")+1:-2]
shift = inputs.index(key[0])
out = ""
print ans
for l in ans:
key = (inputs.index(l)-shift) % len(inputs)
shift += inputs.index(l) % len(inputs)
out += inputs[key]
s.sendall(out[::-1]+"\n")
print s.recv(2048)
print s.recv(2048)
s.sendall("A"*50+"\n")
rec = s.recv(2048)
key = rec[rec.index("[")+1:rec.index("\t")-1]
resp = rec[rec.index("Expected"):]
ans = resp[resp.index("[")+1:-2]
#ans = "".join([chr(0x41+(i%26)) for i in xrange(50)])
off = inputs.index(key[i])
print inputs
print key
out = ""
shift = 0
for j in xrange(0,len(ans),4):
try:
i = j
out += inputs[(inputs.index(ans[i])-inputs.index(key[0])-shift)%len(inputs)]
shift += inputs.index(ans[i])+1
i = j+1
out += inputs[(inputs.index(ans[i])-inputs.index(key[0])-shift)%len(inputs)]
shift += inputs.index(ans[i])+1
i = j+3
out += inputs[(inputs.index(ans[i])-inputs.index(key[0])-shift)%len(inputs)]
shift += inputs.index(ans[i])+1
i = j+2
out += inputs[(inputs.index(ans[i])-inputs.index(key[0])-shift)%len(inputs)]
shift += inputs.index(ans[i])+1
except:
pass
print ans
print out
s.sendall(out+"\n")
rec = s.recv(2048)
key = rec[rec.index("[")+1:rec.index("\t")-1]
resp = rec[rec.index("Expected"):]
print rec
print s.recv(2048)
print s.recv(2048)
print s.recv(2048)
print s.recv(2048)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment