-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar_enc.py
More file actions
31 lines (30 loc) · 902 Bytes
/
Copy pathcaesar_enc.py
File metadata and controls
31 lines (30 loc) · 902 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
abc = "AÁBCDEÉFGHIÍJKLMNOÓÖŐPQRSTUÚÜŰVWXYZ "
def encode(data, key):
data = data.upper()
encrypted_data = ""
if key % len(abc) != 0:
for e in data:
for i in range(len(abc)):
if e == abc[i]:
while True:
if i + key > len(abc):
key -= len(abc)
else:
encrypted_data += abc[i+key]
break
return encrypted_data
else:
return "Nem jó kulcsot adtál meg!"
def decode(data, key):
encrypted_data = ""
data = data.upper()
while True:
if key > len(abc):
key -= len(abc)
else:
break
for e in data:
for i in range(len(abc)):
if e == abc[i]:
encrypted_data += abc[i-key]
return encrypted_data