-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt.py
52 lines (44 loc) · 1.08 KB
/
encrypt.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
plain = "abcdefghijklmnopqrstuvwxyz"
def toCipher( val ):
res = ""
for i in range(0,len(val)):
res += val[ i - 7 ]
return res
cipher = toCipher( plain )
def encrypt( msg ):
res = ""
for i in range(0,len(msg)):
for o in range(0,len(plain)):
if msg[i] == plain[o]:
res += cipher[o]
if msg[i] == " ":
res += " "
return res
def decrypt( msg ):
res = ""
for i in range(0,len(msg)):
for o in range(0,len(cipher)):
if msg[i] == cipher[o]:
res += plain[o]
if msg[i] == " ":
res += " "
return res
def preload():
stat = True
while stat:
cmd = str(input("Encrypt/Decrypt ( E / D )-> "))
if cmd.lower() == "e" or cmd.lower() == "encrypt":
msg = str(input("Message : "))
print(encrypt( msg.lower() ))
elif cmd.lower() == "d" or cmd.lower() == "decrypt":
msg = str(input("Hidden Message : "))
print(decrypt( msg.lower() ))
if __name__ == "__main__":
try:
preload()
except KeyboardInterrupt:
print("\n[ ! ] Interrupted by CTRL + C")
except EOFError:
print("\n[ ! ] EOFError ")
except Exception as e:
print("\n[ ! ] An exection has occured : "+e)