Python RailFenceCipher

RailFenceCipher.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
#coding=utf-8
def railFenceCipher():
e = input()
elen = len(e)
field=[]
for i in range(2,elen):
if(elen%i==0):
field.append(i)
for f in field:
b = int(elen / f)
result = {x:'' for x in range(b)}
for i in range(elen):
a = i % b;
result.update({a:result[a] + e[i]})
d = ''
for i in range(b):
d = d + result[i]
print (d.lower())

if __name__ == '__main__':
try:
while True:
railFenceCipher()
except EOFError:
exit()

评论