Fork me on GitHub

列置换

运行环境python2.7

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
#!usr/bin/env python
#-*- coding:utf-8 -*-
from itertools import *
from optparse import *
def start():
opt = OptionParser()
opt.add_option('-c',dest='content',help='Input your content')
opt.add_option('-o',dest='output',help='File to save the result')
get,args = opt.parse_args()
if get.content is None or get.output is None:
print 'Use \'help\' to get help'
exit(0)
return get.content,get.output
def Exp(content,output):
for i in range(2,len(content)):
if len(content)%i == 0:
filename = open(output,'a+')
getList = Code(i)
getCo = SplitStr(i,content)
for num in getList:
get = ''
for s in getCo:
for one in num:
get = get + s[int(one):int(one)+1]
filename.write(get+'\n')
filename.close()
print 'The result is saved as ' + output
def SplitStr(num,content):
result = []
for i in range(len(content)/num):
result.append(content[i*num:(i+1)*num])
return result
def Code(num):
number = ''
result = []
for i in range(num):
number = number + str(i)
for i in permutations(number,num):
result.append(i)
return result
def main():
content,output = start()
Exp(content,output)
if __name__ == '__main__':
main()

Your support will encourage me to continue to create!