File tree Expand file tree Collapse file tree 4 files changed +45
-2
lines changed Expand file tree Collapse file tree 4 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 33
44def 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
912def 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
1345if __name__ == "__main__" :
Original file line number Diff line number Diff line change 11# pythonchallenge
22Solve 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
616result: http://www.pythonchallenge.com/pc/hex/decent.html
Original file line number Diff line number Diff 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" )
You can’t perform that action at this time.
0 commit comments