-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex2.py
More file actions
32 lines (27 loc) · 835 Bytes
/
Copy pathex2.py
File metadata and controls
32 lines (27 loc) · 835 Bytes
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
ex2_path = "exercise/ex2.enc"
days = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
alphabet = "abcdefghijklmnopqrstuvwxyz"
def cipherSubMessage(cipher, message):
real = ""
if len(cipher) == len(message):
for i in range(len(message)):
real = real + alphabet[(ord(cipher[i])-ord(message[i]))%26]
return real
with open(ex2_path, 'r') as file:
data = file.read().replace('\n', '')
for d in data.split(' '):
for day in days:
key = cipherSubMessage(d, day)
if key != "":
print(key, d, day)
key = "ecms"
starting_point = [0,2,0,3,3,0]
ind = 0
for d in data.split(' '):
pointer = starting_point[ind]
k = ""
for c in d:
k += key[pointer]
pointer = (pointer + 1)%4
print(cipherSubMessage(d, k))
ind += 1