-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryption&dectryption.py
128 lines (117 loc) · 3.55 KB
/
encryption&dectryption.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import random
print("Only alphanumeric characters and spaces can be used ! ")
letters=["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",'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',"0","1","2","3","4","5","6","7","8","9"," "]
enclnum=19
spacerandom=random.randint(19,36)
EorD=input("Do you want to encrypt or dectrypt message?\nE is for encrypt and D for decrypt : ").upper()
def Encryption(message):
codelist=[]
for i in message:
encl0=str(letters.index(i)+enclnum)
encl1=str(letters.index(i)+enclnum-26)
encl2=str(letters.index(" ")+spacerandom)
if letters.index(i)<52:
enccheck=str(i).isupper()
if enccheck:
encl1+="x"
codelist.append(encl1)
else:
encl0+="f"
codelist.append(encl0)
elif letters.index(i)==62:
if random.randint(1,2)==1:
encl2+="f"
codelist.append(encl2)
else:
encl2+="x"
codelist.append(encl2)
else:
if int(letters.index(i))%2==0:
encl0+="y"
codelist.append(encl0)
else:
encl0+="a"
codelist.append(encl0)
code=""
for j in codelist:
code+=j
return code
def Decryption(messagecode):
codeletterlist=[]
slicedcode=[]
enccode=[]
b=""
n=""
indx=[]
crackedcode=""
minilist=[]
m=0
c=0
h=""
q=0
encx=len(messagecode)/3
for i in messagecode:
j=0
j+=1
codeletterlist.append(i)
messagecode=str(messagecode).replace(str(i),"",1)
if j%3==0:
break
for n in range(len(codeletterlist)):
c+=1
minilist.append(codeletterlist[m])
if c%3==0:
for x in minilist:
b+=x
slicedcode.append(b)
minilist.clear()
b=""
m+=1
for i in slicedcode:
n=str(i)
q=int(n.replace(n[-1],""))
if q>80:
indx.append(62)
elif n[-1]=="x":
h=n.replace(n[-1],"")
indx.append(int(h)+26-19)
else:
h=n.replace(n[-1],"")
indx.append(int(h)-19)
for m in indx:
enccode.append(letters[m])
for cl in enccode:
crackedcode+=cl
return crackedcode
if EorD=="E":
input=input("Input your message : ")
input=input.replace(".","")
input=input.replace(",","")
input=input.replace("}","")
input=input.replace("/","")
input=input.replace('"',"")
input=input.replace("(","")
input=input.replace(")","")
input=input.replace("[","")
input=input.replace("]","")
input=input.replace("!","")
input=input.replace("?","")
message=input.replace("{","")
encr1=Encryption(message)
print(encr1)
elif EorD=="D":
input1=input("Input encrypted code,\nEncrypted code can only be from this source : ")
inpu1t=input1.replace(".","")
input1=input1.replace(",","")
input1=input1.replace("}","")
input1=input1.replace("/","")
input1=input1.replace('"',"")
input1=input1.replace("(","")
input1=input1.replace(")","")
input1=input1.replace("[","")
input1=input1.replace("]","")
input1=input1.replace("!","")
input1=input1.replace("?","")
messagecode=input1.replace("{","")
decr1=Decryption(messagecode)
print(decr1)