{
"file_path": "/home/smite/dev/protohackers/10-voracious-code-storage/detailed_analysis.py",
"content": "#!/usr/bin/env python3\n\nimport socket\nimport sys\nimport time\n\ndef detailed_analysis():\n \"\"\"Detailed protocol analysis\"\"\"\n host = 'vcs.protohackers.com'\n port = 30307\n \n print(f\"Connecting to {host}:{port} for detailed analysis...\")\n \n sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n sock.settimeout(10)\n sock.connect((host, port))\n \n # Collect all responses\n all_responses = []\n \n # Get initial response\n initial = sock.recv(1024).decode('ascii', errors='replace')\n all_responses.append(('INITIAL', initial))\n print(f\"Initial: {repr(initial)}\")\n \n # Send various inputs and collect responses\n test_inputs = [\n \"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\",\n \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\",\n \"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\",\n \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\",\n \"0\", \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\",\n \" \", \"!\", \"@\", \"#\", \"$\", \"%\", \"^\", \"&\", \"*\", \"(\", \")\", \"-\", \"=\",\n \"[\", \"]\", \"{\", \"}\", \"|\", \"\\\\\", \";\", \"'\", \":\", \"\\\"\", \",\", \".\", \"/\",\n \"<\", \">\", \"?\", \"~\", \"`\", \"+\", \"_\"\n ]\n \n for char in test_inputs:\n try:\n sock.send(char.encode('ascii'))\n time.sleep(0.05)\n \n response = sock.recv(1024).decode('ascii', errors='replace')\n all_responses.append((char, response))\n print(f\"Sent: {repr(char)} -> Got: {repr(response)}\")\n \n if len(response) == 0:\n print(\"Connection closed\")\n break\n \n except Exception as e:\n print(f\"Error with {repr(char)}: {e}\")\n break\n \n sock.close()\n \n print(\"\\n=== ANALYSIS ===\")\n print(\"Responses collected:\")\n for inp, resp in all_responses:\n print(f\"{repr(inp):>10} -> {repr(resp)}\")\n \n # Look for patterns\n print(\"\\n=== PATTERN ANALYSIS ===\")\n message = ''.join([resp for inp, resp in all_responses if resp and resp != '\\n'])\n print(f\"Combined message: {repr(message)}\")\n \n if message:\n print(f\"Combined readable: {message}\")\n\nif __name__ == \"__main__\":\n detailed_analysis()"
}