-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolve.py
executable file
·65 lines (49 loc) · 1.21 KB
/
solve.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
#!/usr/bin/env python3
import subprocess
def check(pin: str) -> int:
result = subprocess.run(
[
"perf",
"stat",
"-x",
",",
"-e",
"instructions:u",
"../attachments/pin_checker",
],
input=pin,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
text=True,
)
output = result.stderr.split(",")[0]
return int(output)
def find_len() -> int:
pin = ""
max_count = 0
length = 0
for i in range(30):
pin += "0"
count = check(pin)
if count > max_count:
max_count = count
length = i + 1
return length
def find_pin(length: int) -> str:
pin = ""
for _ in range(length):
char = ""
max_count = 0
for code in "0123456789":
paded_pin = (pin + code).ljust(length, "0")
count = check(paded_pin)
print(f"{paded_pin}: {count}")
if count > max_count:
max_count = count
char = code
pin += char
return pin
if __name__ == "__main__":
length = find_len()
pin = find_pin(length)
print("PIN:", pin)