-
Notifications
You must be signed in to change notification settings - Fork 4
/
break,py
49 lines (40 loc) · 1.69 KB
/
break,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
# Import necessary libraries
import hashlib
# Define the public key
p = "04dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff"
# Divide the public key into two subkeys
s1 = p[:len(p)//2]
s2 = p[len(p)//2:]
# Create an empty dictionary to store the results of the first subproblem
results1 = {}
# Solve the first subproblem by trying all possible values for the first half of the key
print("Solving first subproblem...")
for i in range(2**(len(s1)*8)):
# Hash the current value and store the result in the dictionary
results1[hashlib.sha256(i.to_bytes(len(s1), "big")).hexdigest()] = i
print(f"Trying value {i} for s1...")
# Create a flag to track whether the secret key has been found
found = False
# Solve the second subproblem by trying all possible values for the second half of the key
print("Solving second subproblem...")
for i in range(2**(len(s2)*8)):
# Hash the current value
hash = hashlib.sha256(i.to_bytes(len(s2), "big")).hexdigest()
print(f"Trying value {i} for s2...")
# Check if the hash is in the dictionary from the first subproblem
if hash in results1:
# If the hash is in the dictionary, compute the hash of the full secret key
key_hash = hashlib.sha256(results1[hash] + i).hexdigest()
# Check if the hash of the full secret key is equal to the public key
if key_hash == p:
# If the hash of the full secret key is equal to the public key, we have found a solution!
found = True
key = results1[hash] + i
break
# Print the result
if found:
print(f"Secret key found: {key}")
with open("secret.txt", "w") as f:
f.write(key)
else:
print("Secret key not found")