Skip to content

Instantly share code, notes, and snippets.

@ITAYC0HEN
Last active September 5, 2016 15:42
Show Gist options
  • Save ITAYC0HEN/b88bfd6578bde4dcbe236f8ea67f24b7 to your computer and use it in GitHub Desktop.
Save ITAYC0HEN/b88bfd6578bde4dcbe236f8ea67f24b7 to your computer and use it in GitHub Desktop.
[TWCTF-2016: PPC] Make a Palindrome!
# -*- coding:utf-8 -*-
# Server connection example file for Python 2
import socket
import sys
import random
import itertools
# My added data
def makepal(l):
for b in itertools.permutations(l, len(l)):
str1 = ''.join(b)
if str(str1) == str(str1)[::-1]:
print b
return b
#
host = 'ppc1.chal.ctf.westerns.tokyo'
if len(sys.argv) > 1:
host = sys.argv[1]
port = 31111
if len(sys.argv) > 2:
host = int(sys.argv[2])
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((host, port))
client_file = client.makefile('b')
while client_file.readline().strip() != "Let's play!":
pass
client_file.readline()
for case in range(0, 30):
client_file.readline()
words = client_file.readline().split()[2:]
# My added data
answer = makepal(words)
#
client_file.write(' '.join(answer) + "\n")
client_file.flush()
ret = client_file.readline()[8:-1]
print(ret)
if 'Wrong Answer' in ret:
print(client_file.readline())
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment