-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPuzzle.py
122 lines (82 loc) · 3.19 KB
/
getPuzzle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from password import pword
uname = "SanderGott"
import urllib.request
import re
import os
import json
import socket
import requests
file_path = "puzzle.json"
url = "http://www.hacker.org/cross/index.php/"
url = url + "?name=" + uname + "&password=" + pword
def getPuzzle():
with urllib.request.urlopen(url) as response:
html = response.read().decode('utf-8')
# Find line that start with "<script>var boardinit"
puzzle = re.search(r'<script>var boardinit = (.+?);</script>', html).group()
boardinit_match = re.search(r'boardinit = "(.*?)"', puzzle)
level_match = re.search(r'level = (\d+)', puzzle)
# Extract values if they are found
boardinit = boardinit_match.group(1) if boardinit_match else None
level = int(level_match.group(1)) if level_match else None
# print("boardinit:", boardinit) # Output: "1001,1220"
print("Received puzzle for level:", level)
if boardinit and level:
# Check if the file exists; if not, initialize it with an empty dictionary.
if not os.path.exists(file_path):
data = {}
else:
with open(file_path, "r") as f:
data = json.load(f)
if str(level) not in data:
# Update or add the data for the specified level.
data[level] = {
"boardStr": boardinit,
"solution": "",
"posted": False
}
# Write the updated data back to the file.
with open(file_path, "w") as f:
json.dump(data, f, indent=4)
else:
return None
def postPuzzle(level):
with open("puzzle.json", "r") as f:
data = json.load(f)
if str(level) in data:
solution = data[str(level)]
#boardStr = solution["boardStr"]
solution = solution["solution"]
url = "https://www.hacker.org/cross/index.php"
#url = "http://localhost:5000/post-details" # Uncomment if testing locally
# Prepare data as a URL-encoded string
data = f"name={uname}&password={pword}&lvl={level}&sol={solution}"
# Define headers to match the HTTPie request
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Connection": "close",
"User-Agent": "HTTPie"
}
# Send POST request
response = requests.post(url, data=data, headers=headers, allow_redirects=True)
import subprocess
if __name__ == "__main__":
#getPuzzle()
##postPuzzle(13)
#executable = "HackerFlips/bin/Debug/net8.0/HackerFlips.exe"
executable = "FlipsGauus/bin/Release/net8.0/FlipsGauus.exe"
start = 312
#getPuzzle()
#print(postPuzzle(228))
#exit()
while True:
getPuzzle()
# Run the .exe file
result = subprocess.run([executable], capture_output=True, text=True)
# Print the output
print(result.stdout)
#inp = input("Press enter to post puzzle " + str(start) + " or type 'exit' to quit: ")
#if inp == "exit":
# break
postPuzzle(start)
start += 1