-
Notifications
You must be signed in to change notification settings - Fork 28
/
next_clue.py
66 lines (57 loc) · 2.03 KB
/
next_clue.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
import os
import sys
import random
import hashlib
import generate_clues as gc
import subprocess as sp
def shell_out(comm):
return sp.run(comm.split(), capture_output=True).stdout.decode()
def check_hint(clue, hint, dictionary):
if (clue == 3):
count = len(os.listdir("/usr"))
return int(hint) == count
elif (clue == 4):
hostname = open("/etc/hostname", "r").read().strip()
return hint == hostname
elif (clue == 5):
return hint in ["i","n","-i","-n"]
elif (clue == 6):
return hint == os.getenv("PATH").split(":")[0]
elif (clue == 7):
return hint == shell_out("which touch").strip()
elif (clue == 8):
return hint in ["acpi", "denied"]
elif (clue == 9):
val = shell_out(f"wc -l {dictionary}").split()[0]
print(val)
return hint == val
elif (clue == 10):
return hint == shell_out(f"grep -A 1 tactful {dictionary}").strip().split('\n')[1]
elif (clue == 11):
if not hint.startswith("-"):
return False
if not ("k 5" in hint or "k5" in hint):
return False
if not "r" in hint:
return False
if not ("n" in hint or "g" in hint):
return False
return True
if __name__ == "__main__":
if (len(sys.argv) != 4):
sys.exit("Need a secret number, clue number, and hint")
secret_number = int(sys.argv[1])
clue_number = int(sys.argv[2])
hint = sys.argv[3]
clue_indexes = gc.gen_clue_list(gc.START_CLUE, gc.LAST_CLUE,
gc.CLUE_SPACE, secret_number)
dictionary = open("conf", "r").read().strip()
if (check_hint(clue_number, hint, dictionary)):
print(gc.zero_pad(clue_indexes[clue_number - gc.START_CLUE]))
else:
R = random.Random()
if (type(hint) == str):
md5 = hashlib.md5(hint.encode())
hint_number = int(md5.hexdigest(),16)
R.seed(secret_number + clue_number + hint_number)
print(gc.zero_pad(R.randint(1, gc.CLUE_SPACE)))