-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti.py
More file actions
68 lines (55 loc) · 1.36 KB
/
multi.py
File metadata and controls
68 lines (55 loc) · 1.36 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
def cal_k(k):
res = 0
r1 = 26
r2 = k
t1 = 0
t2 = 1
while r2 > 0:
q = int (r1 / r2)
r = r1 - q * r2
t = t1 - q * t2
#print(q, r1, r2, r, t1, t2, t)
r1 = r2
r2 = r
t1 = t2
t2 = t
if r1 == 1 : res = t1
if abs(res) >= 26 :
res = res % 26
if res < 0:
res = 26 + res
else:
if res < 0:
res = 26 + res
return res
#
# a = cal_k(11)
# print(a)
# #
letter_list = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u",
"v", "w", "x", "y", "z"]
plain_text = input("Enter the text : ").strip()
k = int(input("Enter the key : "))
crypto = []
for i in plain_text:
for j in range(len(letter_list)):
if i == letter_list[j]:
crypto.append((j * k) % 26)
print(crypto)
res = []
for i in crypto:
res.append(letter_list[i].upper())
print(res)
cipher_text = input("Enter the Cipher Text : ").strip()
k = int(input("Enter the key : "))
k = cal_k(k)
# print(k)
decrypto = []
for i in cipher_text:
for j in range(len(letter_list)):
if i.lower() == letter_list[j]:
decrypto.append((j * k) % 26)
res = []
for i in decrypto:
res.append(letter_list[i])
print(res)