-
Notifications
You must be signed in to change notification settings - Fork 8
/
DeFence.py
86 lines (40 loc) · 1.1 KB
/
DeFence.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
#!usr/bin/env python
#-*- coding:utf-8 -*-
'''
1.Usage: DeFence.py -c content
2.Usage: DeFence.py -c content -n (A number)
'''
from optparse import OptionParser
def ArgsModule():
Arg = OptionParser()
Arg.add_option('-c',dest='content',help='Input the passwd')
Arg.add_option('-n',dest='num',help='Number of Fence,deault is half of content')
options,args = Arg.parse_args()
if options.content is None:
print 'Please input \'-h\' to get help'
exit(0)
return options
def exp(content,num,quote):
result = []
key = ''
for i in range(quote):
result.append(content[i*num:(i+1)*num])
for n in range(num):
for string in result:
key = key + string[n:n+1]
print key
def DealArgs(options):
if options.num is not None:
quote = len(options.content)/int(options.num)
exp(options.content,int(options.num),quote)
else:
num = len(options.content)/2
for i in range(2,num+1):
if len(options.content)%i == 0:
quote = len(options.content)/i
exp(options.content,i,quote)
def main():
options = ArgsModule()
DealArgs(options)
if __name__ == '__main__':
main()