Last active
September 17, 2016 13:13
-
-
Save seadog007/c8026805bc87595ee23192f51e7b79d7 to your computer and use it in GitHub Desktop.
Tokyo Westerns / MMA CTF 2nd 2016 [Warmup][PPC][20+30pts]Make a Palindrome!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
# Server connection example file for Python 2 | |
import socket | |
import sys | |
import itertools | |
# From http://stackoverflow.com/questions/9952753/single-word-palindrome-checker-true-or-false | |
def is_palindrome(s): | |
return s == s[::-1] | |
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('rw') | |
while client_file.readline().strip() != "Let's play!": | |
pass | |
client_file.readline().strip() | |
for case in range(0, 30): | |
print(client_file.readline().strip()) | |
words = client_file.readline().split()[2:] | |
# words: input | |
# answer: answer | |
## Please write some code here | |
print(words) | |
for i in list(itertools.permutations(words)): | |
if is_palindrome(''.join(i)) == True: | |
answer=i | |
break | |
print(answer) | |
# | |
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) | |
print('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment