-
Notifications
You must be signed in to change notification settings - Fork 0
/
RailFenceCipher.py
50 lines (38 loc) · 942 Bytes
/
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
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
def RailFence(rail, string):
#variable creation
a = []
togetherlist = []
line = 0
column = 0
increment = True
#transform string to list
string_split = list(string)
#matrix creation
for c in range(rail):
a.append( ['|'] * len(string))
#placement of values
while True:
if rail - line == 1:
increment = False
elif line == 0:
increment = True
a[line] [column] = string_split[column]
if increment:
line += 1
else:
line -= 1
if column == len(string) - 1:
break
column += 1
#output
for i in a:
print(i)
#encrypted
for c in range(rail):
while a[c].count('|') > 0:
a[c].remove('|')
for c in range(rail):
togetherlist += a[c]
encrypted= ''.join(togetherlist)
print(encrypted)
return encrypted