File tree Expand file tree Collapse file tree 7 files changed +43
-33
lines changed Expand file tree Collapse file tree 7 files changed +43
-33
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 33
44def main ():
55 left , right = first_step ()
6- second_step (left , right )
6+ diff = second_step (left , right )
7+ third_step (diff )
78
89
910def first_step ():
@@ -22,7 +23,34 @@ def first_step():
2223
2324
2425def second_step (left , right ):
25- pass
26+ diff = difflib .ndiff (left .splitlines (keepends = True ), right .splitlines (keepends = True ))
27+ result = "" .join (diff )
28+ return result
29+
30+
31+ def third_step (diff ):
32+ plus = open ("swan/plus.png" , "wb" )
33+ subtraction = open ("swan/subtraction.png" , "wb" )
34+ space = open ("swan/space.png" , "wb" )
35+ lines = diff .split ("\n " )
36+ for line in lines :
37+ if len (line ) > 0 :
38+ first_byte = line [0 ]
39+ if first_byte == "+" :
40+ write_file (plus , line )
41+ elif first_byte == "-" :
42+ write_file (subtraction , line )
43+ elif first_byte == " " :
44+ write_file (space , line )
45+
46+
47+ def write_file (file , strings ):
48+ sub_strings = strings [2 :]
49+ ary = sub_strings .split (" " )
50+ for point in ary :
51+ if point .isalnum ():
52+ b = bytes .fromhex (point )
53+ file .write (b )
2654
2755
2856if __name__ == "__main__" :
Original file line number Diff line number Diff line change 22Solve Problems in http://www.pythonchallenge.com
33
44#### 18
5+ ``` python
6+ import difflib
7+ ```
58- the obvious different between two picture is brightness.
69
710``` shell
811gunzip deltas.gz
912```
13+ - png file start with: 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A
14+ - 0x89 is png's magic number,all jpg file start with 0xFF
15+ - 0x50 decode in utf-8 is P, 0x4E for N, 0x47 for G
16+ - use three tag "+", "-", " " to describe the difference between two files
17+ > when you say a php file, there is some function in it
18+ - Loop: http://www.pythonchallenge.com/pc/def/linkedlist.php
19+ - RPC: http://www.pythonchallenge.com/pc/phonebook.php
1020
1121#### 17
1222result: http://www.pythonchallenge.com/pc/return/balloons.html
Original file line number Diff line number Diff line change 1- def main ():
2- file = open ("swan/plus.png " , "rb" )
1+ def read_bin_file ():
2+ file = open ("evil/0.jpg " , "rb" )
33 bs = []
44 while True :
55 b = file .read ()
@@ -11,4 +11,4 @@ def main():
1111
1212
1313if __name__ == "__main__" :
14- main ()
14+ read_bin_file ()
You can’t perform that action at this time.
0 commit comments