-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise1.py
More file actions
26 lines (21 loc) · 1.26 KB
/
exercise1.py
File metadata and controls
26 lines (21 loc) · 1.26 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
bank = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz,'?!.$*&0123456789@:+"
def encrypt(message, key):
result = ""
for char in message:
position = bank.find(char)
new_position = (position + key) % len(bank)
result += bank[new_position]
return result
def decrypt(message, key):
result = ""
for char in message:
position = bank.find(char)
new_position = (position - key) % len(bank)
result += bank[new_position]
return result
assert encrypt("test",2) == "vguv"
assert encrypt("encrypted message",42) == "+I@MTKO+:7H+NN8B+"
assert encrypt("This may result as very difficult message, also because as the length increase also the complexity to decrypt this message increases",144) == "PdeoWiXuWnaoqhpWXoWranuW ebbeZqhpWiaooXcawWXhokWYaZXqoaWXoWpdaWhajcpdWejZnaXoaWXhokWpdaWZkilhatepuWpkW aZnulpWpdeoWiaooXcaWejZnaXoao"
assert decrypt("vguv",2) == "test"
assert decrypt("+I@MTKO+:7H+NN8B+",42) == "encrypted message"
assert decrypt("PdeoWiXuWnaoqhpWXoWranuW ebbeZqhpWiaooXcawWXhokWYaZXqoaWXoWpdaWhajcpdWejZnaXoaWXhokWpdaWZkilhatepuWpkW aZnulpWpdeoWiaooXcaWejZnaXoao",144) == "This may result as very difficult message, also because as the length increase also the complexity to decrypt this message increases"