-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrail_fence.py
More file actions
67 lines (59 loc) · 1.53 KB
/
rail_fence.py
File metadata and controls
67 lines (59 loc) · 1.53 KB
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
#!/usr/bin/env python
import math
def get_message():
message = raw_input("Enter message : ")
get_key(message)
def get_key(message):
key = input("Enter the depth : ")
mode = raw_input("Enter E/e for encryption and D/d for decryption : ")
helper(message , key , mode)
def helper(message , key , mode):
space_li = ""
for char in message:
if ord(char) >= 97 and ord(char) <= 122:
space_li += char
print space_li
#length = len(space_li)
#div = float(length) / float(key)
#no_of_rows = math.ceil(div)
i = 0
mod = ""
rem = ""
remm = ""
cipher = ""
#print mode
if mode == 'E' or mode == 'e':
for char in space_li:
if i < len(space_li):
if i % key == 0:
mod += char
elif i % key == 1:
rem += char
else:
remm += char
i += 1
cipher = mod + rem + remm
print cipher
elif mode == 'D' or mode == 'd':
for char in space_li:
if i < len(space_li):
if i % key == 0:
mod += char
elif i % key == 1:
rem += char
else:
remm += char
i += 1
cipher = mod + rem + remm
print cipher
else:
print "Wrong choice!!!!"
get_message()
'''
a = []
for i in range(3):
a.append([])
for j in range(3):
a[i].append(i + j)
print a
'''