-
Notifications
You must be signed in to change notification settings - Fork 2
/
Decrypt.py
85 lines (78 loc) · 2.74 KB
/
Decrypt.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
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
from cryptography.fernet import Fernet
import os
def DAES(key,iv):
f=open(os.path.join(os.getcwd()+"/Parts","0.txt"),"rb")
content=f.read()
f.close()
backend = default_backend()
cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=backend)
decryptor = cipher.decryptor()
content=decryptor.update(content) + decryptor.finalize()
f=open(os.path.join(os.getcwd()+"/Parts","0.txt"),"wb")
f.write(content)
f.close()
def DBlowFish(key,iv):
f=open(os.path.join(os.getcwd()+"/Parts","1.txt"),"rb")
content=f.read()
f.close()
backend = default_backend()
cipher = Cipher(algorithms.Blowfish(key), modes.CBC(iv), backend=backend)
decryptor = cipher.decryptor()
content=decryptor.update(content) + decryptor.finalize()
f=open(os.path.join(os.getcwd()+"/Parts","1.txt"),"wb")
f.write(content)
f.close()
def DTrippleDES(key,iv):
f=open(os.path.join(os.getcwd()+"/Parts","2.txt"),"rb")
content=f.read()
f.close()
backend = default_backend()
cipher = Cipher(algorithms.TripleDES(key), modes.CBC(iv), backend=backend)
decryptor = cipher.decryptor()
content=decryptor.update(content) + decryptor.finalize()
f=open(os.path.join(os.getcwd()+"/Parts","2.txt"),"wb")
f.write(content)
f.close()
def DIDEA(key,iv):
f=open(os.path.join(os.getcwd()+"/Parts","3.txt"),"rb")
content=f.read()
f.close()
backend = default_backend()
cipher = Cipher(algorithms.IDEA(key), modes.CBC(iv), backend=backend)
decryptor = cipher.decryptor()
content=decryptor.update(content) + decryptor.finalize()
open(os.path.join(os.getcwd()+"/Parts","3.txt"),"wb").close()
f=open(os.path.join(os.getcwd()+"/Parts","3.txt"),"wb")
f.write(content)
f.close()
def DFernet(key):
f=open(os.path.join(os.getcwd()+"/Parts","4.txt"),"rb")
content=f.read()
f.close()
fer = Fernet(key)
content=fer.decrypt(content)
open(os.path.join(os.getcwd()+"/Parts","4.txt"),"w").close()
f=open(os.path.join(os.getcwd()+"/Parts","4.txt"),"wb")
f.write(content)
f.close()
def DeCryptKeys():
f=open('Secured.txt','rb')
key=f.read()
f.close()
fer = Fernet(key)
listDir=os.listdir(os.path.join(os.getcwd(),"Keys_IV"))
for i in listDir:
path=os.path.join(os.getcwd()+"/Keys_IV",i)
print(path)
k=open(path,"rb")
content=k.read()
print(content)
k.close()
content=fer.decrypt(content)
open(os.path.join(os.getcwd()+"/Keys_IV",i),"wb").close()
f=open(os.path.join(os.getcwd()+"/Keys_IV",i),"wb")
print(i)
f.write(content)
f.close()