-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPolyalphabitec_Cipher.py
More file actions
79 lines (72 loc) · 2.73 KB
/
Polyalphabitec_Cipher.py
File metadata and controls
79 lines (72 loc) · 2.73 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
while True:
ch = int(input("Press 1 for encrypt || 2 for decrypt:-\n>>>"))
if ch == 1:
text = input("Text:").lower()
sliced=[]
for tx in range(len(text)//2):
if text[tx*3:tx*3+3] != '':
sliced.append(text[tx*3:tx*3+3])
listed=[list(sl) for sl in sliced]
encrypt=[]
for li in listed:
for i, x in enumerate(li):
if i==0:
x = ord(x)+3
if x > ord('z'):
x -=26
encrypt.append(chr(x))
else:
encrypt.append(chr(x))
elif i==1:
x = ord(x)+5
if x > ord('z'):
x -=26
encrypt.append(chr(x))
else:
encrypt.append(chr(x))
elif i==2:
x = ord(x)+7
if x > ord('z'):
x -=26
encrypt.append(chr(x))
else:
encrypt.append(chr(x))
print("==========================================")
print(" !!! Encrypted !!! ")
print("".join(encrypt))
print("==========================================\n")
elif ch == 2:
text = input("Text:").lower()
sliced=[]
for tx in range(len(text)//2):
if text[tx*3:tx*3+3] != '':
sliced.append(text[tx*3:tx*3+3])
listed=[list(sl) for sl in sliced]
decrypt=[]
for li in listed:
for i, x in enumerate(li):
if i==0:
x = ord(x)-3
if x < ord('a'):
x +=26
decrypt.append(chr(x))
else:
decrypt.append(chr(x))
elif i==1:
x = ord(x)-5
if x < ord('a'):
x +=26
decrypt.append(chr(x))
else:
decrypt.append(chr(x))
elif i==2:
x = ord(x)-7
if x < ord('a'):
x +=26
decrypt.append(chr(x))
else:
decrypt.append(chr(x))
print("==========================================")
print(" !!! Decrypted !!! ")
print("".join(decrypt))
print("==========================================\n")