-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeDecrypt.py
More file actions
65 lines (52 loc) · 1.99 KB
/
Copy pathcodeDecrypt.py
File metadata and controls
65 lines (52 loc) · 1.99 KB
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
import sys
import base64
from codeUtilities import *
usage = "Uso: {0} {1}".format(sys.argv[0], '[archivo]')
class codeDecrypt(object):
def __init__(self, data, key):
self.data = data
self.key = key
# Decrypt a block of 32 bytes
def decryptBlock(self, block):
return codeUtilities.operate( base64.b64decode(block),self.key )
def decryptText(self):
message = "\nMessage: "
arrayBlock = ""
for b in self.data:
if len(arrayBlock) < 44:
arrayBlock += b
else:
message += self.decryptBlock(arrayBlock).decode("utf-8")
arrayBlock = b
message += self.decryptBlock(arrayBlock).decode("utf-8")
print(message)
def decryptFile(self):
ext = self.data.split(".")[len(self.data.split("."))-1]
inputFile = open(self.data,"r")
finalFile = open("{0}.{1}".format("decrypt",ext),"wb")
arrayBlock = ""
# Read file in blocks of 32 bytes
for l in inputFile:
for b in l:
if len(arrayBlock) < 44:
arrayBlock += b
else:
# Write the decrypted block
finalFile.write( self.decryptBlock(arrayBlock) )
arrayBlock = b
finalFile.write( self.decryptBlock(arrayBlock) )
inputFile.close()
finalFile.close()
if __name__ == "__main__":
if len(sys.argv) > 1:
print ()
print ("\t---- Welcome to CodeCrypt 1.1 ----")
e = codeDecrypt(sys.argv[1], codeUtilities.generateKey(sys.argv[2]))
print ("\nProceeding to decrypt...")
if (len(sys.argv) > 3 and sys.argv[3].lower() == "file"):
e.decryptFile()
else:
e.decryptText()
print ("\nSuccess")
else:
print (usage)