forked from cyberpvn7/Python_Lang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar_cipher.py
More file actions
41 lines (34 loc) · 766 Bytes
/
caesar_cipher.py
File metadata and controls
41 lines (34 loc) · 766 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
33
34
35
36
37
38
39
40
41
k = [chr(ord("A")+i) for i in range(26)]
v = [i for i in range(26)]
d = {k[i] : v[i] for i in range(26)}
def get_key(val):
for key,value in d.items():
if(value == val):
return key
def encrypt(pt):
key = 7
li = []
for i in pt:
li.append((d[i] + key)%26)
for i in range(len(li)):
li[i] = get_key(li[i])
# print(li)
st = ""
for i in li:
st += i
# print(st)
return st
def decrypt(pt):
st = ""
for i in range(len(pt)):
a = d[pt[i]] - 7
if(a < 0):
a += 26
st += get_key(a)
# print(st)
return st
pt = input("Enter plain text(Don't Add Space): ")
pt = pt.upper()
a = encrypt(pt)
print("Encrypted Message:",a)
print("Decrypted Message:",decrypt(a))