forked from AdrainYe/CTF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hill.py
192 lines (124 loc) · 2.54 KB
/
Hill.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python
#-*- coding:utf-8 -*-
'''
'''
from numpy import *
from optparse import OptionParser
def Start():
opt = OptionParser()
opt.add_option('-k',dest='key',help="Input your matrix")
opt.add_option('-p',dest='pw',help="Input your passwd")
options,args = opt.parse_args()
if options.pw is None or options.key is None:
print 'Use \'-h\' to get help'
exit(0)
return options
def ForKey(key):
key = mat(key)
key = key.I.T
print 'key is :'
print key
print '------------------------------------------'
return key
def ForPw(pw,lenght):
result = [[] for i in range(len(pw)/lenght)]
for i in range(len(pw)/lenght):
string = pw[i*lenght:(i+1)*lenght]
for s in string:
if s.isalpha():
s = ord(s) - 96
result[i].append(s)
result = mat(result)
print 'password matrix is:'
print result
print '------------------------------------------'
return result
def Deal(start):
key = start.key
pw = start.pw
if pw.isalpha():
judge = True
key = ForKey(key)
result = ForPw(pw,len(key))
return key,result,judge
def Exploit(key,result,judge):
get = result * key
print 'The result matrix is:'
print get
print '------------------------------------------'
get = array(get)
string = ''
for n in get:
for i in n:
one = int(i)
while one < 0:
one = one + 26
one = one + 96
string = string + chr(one)
print 'The final result is:\n' + string
def main():
start = Start()
key,result,judge = Deal(start)
Exploit(key,result,judge)
if __name__ == '__main__':
main()
'''
Usage:
python Hill.py -k '1,2;0,1' -p dloguszijluswogany
key is :
[[ 1. 0.]
[-2. 1.]]
------------------------------------------
password matrix is:
[[ 4 12]
[15 7]
[21 19]
[26 9]
[10 12]
[21 19]
[23 15]
[ 7 1]
[14 25]]
------------------------------------------
The result matrix is:
[[-20. 12.]
[ 1. 7.]
[-17. 19.]
[ 8. 9.]
[-14. 12.]
[-17. 19.]
[ -7. 15.]
[ 5. 1.]
[-36. 25.]]
------------------------------------------
The final result is:flagishillissoeapy
meizhi@ubuntu:~/ctf$ python Hill.py -k '1,2;0,1' -p dloguszijluswogany
key is :
[[ 1. 0.]
[-2. 1.]]
------------------------------------------
password matrix is:
[[ 4 12]
[15 7]
[21 19]
[26 9]
[10 12]
[21 19]
[23 15]
[ 7 1]
[14 25]]
------------------------------------------
The result matrix is:
[[-20. 12.]
[ 1. 7.]
[-17. 19.]
[ 8. 9.]
[-14. 12.]
[-17. 19.]
[ -7. 15.]
[ 5. 1.]
[-36. 25.]]
------------------------------------------
The final result is:
flagishillissoeapy
'''