-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathcolumnar.py
More file actions
48 lines (42 loc) · 1.07 KB
/
columnar.py
File metadata and controls
48 lines (42 loc) · 1.07 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
def sort_list(list1, list2):
pairs = zip(list2, list1)
z = [x for _, x in sorted(pairs)]
return z
def encrpyt(key, msg):
key_arr = []
for i in key:
key_arr.append(i)
msg_arr = []
temp = []
for i in msg:
if(len(temp) == len(key_arr)):
msg_arr.append(sort_list(temp, key_arr))
temp = []
temp.append(i)
cipher = ''
for i in range(len(msg_arr[0])):
for j in range(len(msg_arr)):
cipher = cipher + msg_arr[j][i]
return cipher
def decrpyt(key, cipher):
key_arr = []
for i in key:
key_arr.append(i)
n = int(len(cipher)/len(key))
msg_arr = []
for i in range(n):
msg_arr.append([])
for i in range(len(cipher)):
msg_arr[i % (len(key)-1)].append(cipher[i])
final = []
for i in msg_arr:
final.append(sort_list(i, key_arr))
msg = ''
for i in final:
for j in i:
msg = msg + j
return msg
cipher = encrpyt("dcba", "hello world ")
print(cipher)
message = decrpyt("dcba", cipher)
print(message)