-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplementation_of_ceasercipher.py
More file actions
48 lines (38 loc) · 1.28 KB
/
implementation_of_ceasercipher.py
File metadata and controls
48 lines (38 loc) · 1.28 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
# # Encryption
def encrypt(message='CRYPTOCURRENCY',key=3):
cipher_text=''
for char in message:
if char==' ':
char=char
cipher_text=cipher_text + char
elif char.isupper():
s=ord(char)
char= ((s+key-65)%26+65)
char=chr(char)
cipher_text=cipher_text + char
else:
s=ord(char)
char= ((s+key-97)%26+97)
char=chr(char)
cipher_text=cipher_text + char
return cipher_text
print(f'The cipher text of given message after encryption process is {encrypt()}')
# Decryption
def decrypt(message=encrypt(),key=3):
plain_text=''
for char in message:
if char==' ':
char=char
plain_text=plain_text + char
elif char.isupper():
s=ord(char)
char= ((s-key-65)%26+65)
char=chr(char)
plain_text=plain_text + char
else:
s=ord(char)
char= ((s-key-97)%26+97)
char=chr(char)
plain_text=plain_text + char
print(f'The plain text after decryption process is {plain_text}')
decrypt()