-
Notifications
You must be signed in to change notification settings - Fork 5
/
DataShield.py
134 lines (80 loc) · 3.77 KB
/
DataShield.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
import pyAesCrypt
from os import stat, remove
print("****************************************************************************")
print("\t \t \t MENU")
print("***************************************************************************")
print("\t \t 1. Data XOR Encryption and Decryption ")
print("\t \t 2. Data AES Encryption and Decryption ")
print("***************************************************************************")
a=int(input("Enter your choice"))
if a==1:
print("*************************************")
print("1.Press 1 for Encryption")
print("1.Press 2 for Dencryption")
b=int(input("Enter your choice"))
if b==1:
try:
path = input(r'Enter path of data: ')
key = int(input('Enter Key for encryption of data : '))
print('The path of file : ', path)
print('Key for encryption : ', key)
fin = open(path, 'rb') #Reading Binary value of fetched file/image
image = fin.read()
fin.close()
image = bytearray(image)#typecasting
for index, values in enumerate(image):
image[index] = values ^ key
fin = open(path, 'wb') #Writing Binary value of fetched file/image
fin.write(image)
fin.close()
print('Encryption Done...')
except Exception:
print('Error caught : ', Exception.__name__)
if b==2:
try:
path = input(r'Enter path of data : ')
key = int(input('Enter Key for encryption of data : '))
print('The path of file : ', path)
print('Note : Encryption key and Decryption key must be same.')
print('Key for Decryption : ', key)
fin = open(path, 'rb') #Reading Binary value of fetched file/image
image = fin.read()
fin.close()
image = bytearray(image)
for index, values in enumerate(image):
image[index] = values ^ key
fin = open(path, 'wb')
fin.write(image)
fin.close()
print('Decryption Done...')
except Exception:
print('Error caught : ', Exception.__name__)
else:
print("Please enter the Right choice")
if a==2:
print("**********************************************************************************************")
print("1 for Encryption" )
print("2 for Decryption")
print("##############################################################################################")
h=int(input("Enter the Choice"))
jh=input("Enter the file location with extension")
bufferSize = 64 * 1024 #by default 512 (max value 64*1024)
password = input("Enter the password")
koi=f'{jh}.aes'
if h==1:
with open(jh, "rb") as fIn:
with open(koi, "wb") as fOut:
pyAesCrypt.encryptStream(fIn, fOut, password, bufferSize)
print("Encryption done")
if h==2:
#DEcrypt................
encFileSize = stat(jh).st_size
print(encFileSize)
with open(jh, "rb") as fIn:
try:
aso=input("decrrypted file name")
with open(aso, "wb") as fOut:
# decrypt file stream
pyAesCrypt.decryptStream(fIn, fOut, password, bufferSize, encFileSize)
except ValueError:
print("Value Error please give less buffer Size Block")