-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcipher.py
58 lines (55 loc) · 1.51 KB
/
cipher.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
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
if __name__=="main":
pass
def enc(password):
#print("hello")
grid = {}
key = 33
index = []
for x in range(1, 4):
c = x
for y in range(1, 9):
b = y
for z in range(1, 5):
a = z
index = []
for f in (c, b, a):
index.append(str(f))
grid[chr(key)] = index
key += 1
#global grid
encryption = []
for p in range(0, len(password)):
encryption.append("".join(grid[password[p]])) # encrypts the pass
return "".join(encryption) # prints encrypted pass
def dec(sam):
#print("hello")
grid = {}
key = 33
index = []
for x in range(1, 4):
c = x
for y in range(1, 9):
b = y
for z in range(1, 5):
a = z
index = []
for f in (c, b, a):
index.append(str(f))
grid[chr(key)] = index
key += 1
decryption = []
#print(sam)
ecn_pass = str(sam) #will be changed to a var taking ecrypted_pass as input
n = 0
dec = []
for g in range(0, int(len(ecn_pass)/3)):
dec = []
for e in range(n, n+3):
dec.append(ecn_pass[e])
decryption.append(dec)
n = n + 3
#print(decryption)
d = []
for h in range(0, len(decryption)):
d.append(list(grid.keys())[list(grid.values()).index(decryption[h])]) #prints decrypted pass
return "".join(d)