-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaesar.py
29 lines (27 loc) · 886 Bytes
/
caesar.py
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
def encrypt_caesar(plaintext):
ciphertext = ""
for i in plaintext:
if (ord(i) + 3 > ord("Z")) and (ord(i) + 3 < ord("a")):
ciphertext += chr(ord(i)+3-26)
else:
if ord(i) + 3 > ord("z"):
ciphertext += chr(ord(i) + 3 - 26)
else:
ciphertext += chr(ord(i) + 3)
return ciphertext
primer = input()
primer = encrypt_caesar(primer)
print(primer)
def decrypt_caesar(ciphertext):
plaintext = ""
for i in ciphertext:
if (ord(i) - 3 < ord("a")) and (ord(i) - 3 > ord("Z")):
plaintext += chr(ord(i) - 3 + 26)
else:
if ord(i) - 3 < ord("A"):
plaintext += chr(ord(i) - 3 + 26)
else:
plaintext += chr(ord(i) - 3)
return plaintext
primer2 = input()
print(decrypt_caesar(primer2))