-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryptdecfile.py
111 lines (70 loc) · 2.74 KB
/
encryptdecfile.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
class code:
def __init__(self):
self.codes={'a':'z','b':'x','c':'y','d':'s','e':'u','f':'a','g':'e','h':'c','i':'k','j':'r','k':'n','l':'g','m':'d','n':'l','o':'m','p':'t','q':'f','r':'i','s':'h','t':'o','u':'j','v':'p','w':'v','x':'b','y':'w','z':'q'}
self.first=[]
self.enc=[]
self.en=[]
self.dec1=[]
self.dec2=[]
def option(self):
q=str(input("encrypt or decrypt:"))
if q == "encrypt":
text=str(input("enter text:"))
self.encrypt(text)
else:
text=str(input("enter text:"))
self.decrypt(text)
def encrypt(self,text):
x=text.split(" ")
y=x[::-1]
z=""
for i in range(0,len(y)):
string = "".join(reversed(y[i]))
z+=string
z+=" "
for i in z:
self.en.append(i)
for i in range(0,len(self.en)):
for j in self.en[i]:
if j !=' ':
for key in self.codes.keys():
if key in j:
self.enc.append(self.codes.get(key))
else:
self.enc.append("/s")
encrypt=" "
for i in range(0,len(self.enc)):
if self.enc[i]=="/s":
encrypt+=" "
else:
encrypt+=self.enc[i]
print("your encrypted text:",encrypt)
def decrypt(self,text):
z=[]
for i in text:
z.append(i)
for i in range(0,len(z)):
for j in z[i]:
if j!=" ":
if j in self.codes.values():
self.dec1.append(list(self.codes.keys())[list(self.codes.values()).index(z[i])])
else:
self.dec1.append("/s")
z=""
for i in range(0,len(self.dec1)):
if self.dec1[i]=="/s":
z+=" "
else:
z+=self.dec1[i]
y=z.split(" ")
for i in y:
self.dec2.append(i)
rev=self.dec2[::-1]
rever=""
for i in range(0,len(rev)):
string = "".join(reversed(rev[i]))
rever+=string
rever+=" "
print("decrypted text:",rever)
ob=code()
ob.option()