1
1
import download_file
2
2
3
3
from PIL import Image
4
+ import bz2
5
+ import py2keywords
4
6
5
7
6
8
def main ():
@@ -10,9 +12,12 @@ def main():
10
12
user = "butter"
11
13
password = "fly"
12
14
# first_step(url, file_path, user, password)
13
- raw ,result = second_step (file_path )
15
+ im , raw ,result = second_step (file_path )
14
16
raw_ary ,result_ary = third_step (raw ,result )
15
- fourth_step (raw_ary ,result_ary )
17
+ raw_str ,result ,index = fourth_step (raw_ary ,result_ary )
18
+ hint_path = "zigzag/{}" .format ("hint.png" )
19
+ five_step (im ,index ,hint_path )
20
+ six_step (raw_str )
16
21
17
22
18
23
def first_step (url ,file_path ,user ,password ):
@@ -27,7 +32,7 @@ def second_step(file_path):
27
32
value = "" .join ([chr (palette [i ])for i in range (len (palette ))])
28
33
table = str .maketrans (index ,value )
29
34
result = raw .decode ("latin1" ).translate (table ).encode ("latin1" )
30
- return raw ,result
35
+ return im , raw ,result
31
36
32
37
33
38
def third_step (raw ,result ):
@@ -42,7 +47,44 @@ def third_step(raw, result):
42
47
43
48
44
49
def fourth_step (raw_ary ,result_ary ):
45
- pass
50
+ zero = raw_ary .pop (0 )
51
+ raw_ary .append (zero )
52
+ assert len (raw_ary )== len (result_ary )
53
+ raw = []
54
+ result = []
55
+ index = []
56
+ for i in range (len (raw_ary )):
57
+ raw_i = raw_ary [i ]
58
+ result_i = result_ary [i ]
59
+ if raw_i != result_i :
60
+ raw .append (raw_i )
61
+ result .append (result_i )
62
+ index .append (i )
63
+ raw_str = b""
64
+ for i in range (len (raw )):
65
+ raw_str += chr (raw [i ]).encode ("latin1" )
66
+ return raw_str ,result ,index
67
+
68
+
69
+ def five_step (im ,index ,hint_path ):
70
+ im2 = Image .new ("RGB" ,im .size )
71
+ colors = [(255 ,255 ,255 )]* (im2 .size [0 ]* im2 .size [1 ])
72
+ for i in index :
73
+ colors [i ]= (0 ,0 ,255 )
74
+ im2 .putdata (colors )
75
+ im2 .save (hint_path )
76
+ print ("Hint in {}" .format (hint_path ))
77
+
78
+
79
+ def six_step (raw_str ):
80
+ raw_dec = bz2 .decompress (raw_str )
81
+ strs = raw_dec .decode ("latin1" ).split (" " )
82
+ results = set ()
83
+ for i in range (len (strs )):
84
+ s = strs [i ]
85
+ if not s in py2keywords .kwlist :
86
+ results .add (s )
87
+ print (results )
46
88
47
89
48
90
if __name__ == "__main__" :