-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUniversal_file_Encrypter_2.0.py
172 lines (142 loc) · 5.86 KB
/
Universal_file_Encrypter_2.0.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import datetime
import pickle
class info_protect:
def __init__(self,path,mode):
self.passfile=str(input("Enter the passfile name:"))
self.path=path
self.mode=mode
self.inbytes=bytearray(open(self.path,'rb').read())
self.outbytes=bytearray()
self.basebytes=bytearray(range(256))*2
self.temp=[]
self.venue=''
self.date=''
self.time=''
self.file=self.path.split('.')
self.dest=''
self.inbytes2=bytearray()
self.extension=self.file[-1]
if len(self.file)>2:
self.fil_name='.'.join(self.file[:len(self.file)-1])
else:
self.fil_name=self.file[0]
self.passkey=bytearray(open(self.passfile,'rb').read())
def encrypt(self):
a=-1
while True :
try:
a+=1
if a==0 :
file=open(self.fil_name+'.secure02','rb')
else:
file=open(self.fil_name+str(a)+'.secure02','rb')
except IOError :
if a==0 :
self.dest=self.fil_name+'.secure02'
file=open(self.dest,'wb')
else:
self.dest=self.fil_name+str(a)+'.secure02'
file=open(self.dest,'wb')
break
file.close()
file=open('$temp.dat','wb')
pickle.dump(self.inbytes,file)
pickle.dump(self.extension,file)
#pickle.dump(self.inbytes,file)
file.close()
self.inbytes2=bytearray(open('$temp.dat','rb').read())
for i in range(len(self.inbytes2)):
val=self.inbytes2[i]+self.passkey[i%len(self.passkey)]
self.outbytes.append(self.basebytes[val])
file=open(self.dest,'wb')
file.write(self.outbytes)
file.close()
def decrypt(self):
for i in range(len(self.inbytes)):
val=self.inbytes[i]-self.passkey[i%len(self.passkey)]
self.outbytes.append(self.basebytes[val])
file=open('$temp.dat','wb')
file.write(self.outbytes)
file.close()
file=open('$temp.dat','rb')
self.outbytes=pickle.load(file)
self.extension=pickle.load(file)
file.close()
file=open(self.fil_name+'_decrypted'+'.'+self.extension,'wb')
file.write(bytearray(self.outbytes))
file.close()
def process(self):
if self.mode=="Enc":
self.encrypt()
elif self.mode=="Dec":
self.decrypt()
self.venue=str(datetime.datetime.now())
self.date,self.time=self.venue.split(' ')
self.time=self.time.split(':')
if int(self.time[0])>=12 :
if int(self.time[0])==12:
self.time=str(int(self.time[0]))+':'+self.time[1]+' PM'
else:
self.time=str(int(self.time[0])%12)+':'+self.time[1]+' PM'
else:
self.time=self.time[0]+':'+self.time[1]+ ' AM' + ' , ' + self.time[2] + ' sec'
try:
#global file
file1=open("univlogv2.dat",'rb')
file1.close()
file1=open("univlogv2.dat",'ab')
except IOError:
file1=open("univlogv2.dat",'ab')
while True :
print('------------------------------------------------------------------------------------------------------------')
choice=int(input("\n\n\nTo encrypt enter 1, to decrypt enter 2 , to view log enter 3 , to quit enter any other number :"))
if choice==1 :
print('Please Ensure That the password file is smaller than input file for encryption')
try:
enc_file=info_protect(input('\n Enter the path name of file :'),'Enc')
enc_file.process()
pickle.dump(enc_file.path,file1)
pickle.dump(enc_file.passfile,file1)
pickle.dump(enc_file.mode,file1)
pickle.dump(enc_file.date,file1)
pickle.dump(enc_file.time,file1)
except IOError :
print('\nPlease enter a valid path name next time!!!')
else:
print("\nFile Successfully Encrypted!!")
elif choice==2 :
try:
dec_file=info_protect(input('\n Enter the path name of file :'),'Dec')
dec_file.process()
pickle.dump(dec_file.path,file1)
pickle.dump(dec_file.passfile,file1)
pickle.dump(dec_file.mode,file1)
pickle.dump(dec_file.date,file1)
pickle.dump(dec_file.time,file1)
except IOError :
print('\nPlease enter a valid path name next time!!!')
else:
print("\nFile Successfully Decrypted!!")
elif choice==3 :
try:
file1.close()
file1=open("univlogv2.dat",'rb')
a=1
while True :
print('========================Entry %d=========================='%(a))
print('\nFile path :'+' '+pickle.load(file1))
print('\nPassfile path :'+' '+pickle.load(file1))
print('\nProcess :'+' '+pickle.load(file1)+'ryption')
print('\nDate :'+' '+pickle.load(file1))
print('\nTime :'+' '+pickle.load(file1))
print()
print('==========================================================')
a+=1
except EOFError :
if a==1:
print("No Records found")
else:
print("\nThat's it---------")
else :
print("\nThanks for using me!!!!!!!!!")
break