Skip to content

Commit b70d52b

Browse files
solved 26
1 parent 8bf54cf commit b70d52b

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

26.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,43 @@
33

44
def main():
55
file_path = "maze/maze/mybroken.zip"
6-
first_step(file_path)
6+
result_file_path = "maze/maze/my.zip"
7+
email_md5 = "bbb8b499a0eef99b52c7f13f4e78c24b"
8+
# first_step(file_path)
9+
second_step(email_md5, file_path, result_file_path)
710

811

912
def first_step(file_path):
1013
file = open(file_path, "rb")
14+
get_bytes_md5(file.read())
15+
16+
17+
def second_step(target, file_path, result_file_path):
18+
file = open(file_path, "rb")
19+
bs = file.read()
20+
finished = False
21+
for i in range(len(bs)):
22+
for j in range(256):
23+
bs_head = bs[: i]
24+
bs_center = chr(j).encode("latin1")
25+
bs_tail = bs[i + 1:]
26+
new_bs = bs_head + bs_center + bs_tail
27+
now = get_bytes_md5(new_bs)
28+
if now == target:
29+
result_file = open(result_file_path, "wb")
30+
result_file.write(bs)
31+
print("Done! result={}".format(result_file_path))
32+
finished = True
33+
break
34+
if finished:
35+
break
36+
37+
38+
def get_bytes_md5(hex_string):
39+
mymd5 = hashlib.md5()
40+
mymd5.update(hex_string)
41+
hexdigest = mymd5.hexdigest()
42+
return hexdigest
1143

1244

1345
if __name__ == "__main__":

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# pythonchallenge
22
Solve Problems in http://www.pythonchallenge.com
33

4+
#### 26
5+
result: http://www.pythonchallenge.com/pc/hex/speedboat.html
6+
```python
7+
import hashlib
8+
```
9+
- we get mybroken.zip in level 24
10+
- the decent means leopold mozart
11+
- we have sent an email to leopold mozart in level 19
12+
- fix the broken zip file to match the md5
13+
414

515
#### 25
616
result: http://www.pythonchallenge.com/pc/hex/decent.html

maze/maze/my.zip

2.64 KB
Binary file not shown.

read-bin-file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ def read_bin_file(file_path):
1818
# read_bin_file("indian/indian.wav")
1919
# read_bin_file("indian/result.wav")
2020
# read_bin_file("maze/maze/mybroken.gif")
21-
read_bin_file("lake/lake1.jpg")
21+
# read_bin_file("lake/lake1.jpg")
22+
read_bin_file("maze/maze/mybroken.zip")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy