Skip to content

Instantly share code, notes, and snippets.

@datbmt
Created August 19, 2018 12:57
Show Gist options
  • Select an option

  • Save datbmt/180f5a040fadda134d5a03c3b9de6fca to your computer and use it in GitHub Desktop.

Select an option

Save datbmt/180f5a040fadda134d5a03c3b9de6fca to your computer and use it in GitHub Desktop.
host = 'misc04.grandprix.whitehatvn.com'
port = 1337
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
def recv_until(s,st):
tmp=''
while st not in tmp:
tmp+=s.recv(1)
return tmp
recv_until(s, 'Now play!\n')
while 1:
print recv_until(s, 'Face_index: ')
n = face_index = int(recv_until(s, 'Face').replace('Face', '').strip())
phi = euler_phi(n)
recv_until(s, 'Forehead point \n')
tmp = recv_until(s, 'So, what is the most friendly face?\n')[:-37]
max_value = 0
res = ''
for i in tmp.strip().split('\n'):
i = i.strip()
while " " in i:
i = i.replace(' ', " ")
a,b,c,d,e = i.strip().split(' ')
b, c, d, e = int(b), int(c), int(d), int(e)
face_value = Integer(pow(Integer(pow(b,c,n)), Integer(pow(d, e, phi)), n) % n)
if face_value > max_value:
max_value = face_value
res = a
s.send(res+'\n')
print recv_until(s, '''It's friendly point\n''')
s.send(str(max_value) + '\n')
print s.recv(1024)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment