forked from prateekiiest/Code-Sleep-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·52 lines (43 loc) · 1.21 KB
/
main.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
from readfiles import *
from AES256 import *
import argparse
from argparse import RawTextHelpFormatter
import time
parser = argparse.ArgumentParser(description='AES 256-bit encrypt and decrypt', formatter_class=RawTextHelpFormatter)
parser.add_argument('mode',help="encrypt or decrypt")
args = parser.parse_args()
mode = str(args.mode).lower()
def fileEncrypt():
block = getEncryptBlock("testBlock")
key = getKey("testKey")
outfile = open("encrypted_file","wb")
strangen = ""
cryptLargeblock = []
for i in range(len(block)):
cryptLargeblock.append(encrypt(block[i],key))
while i < len(cryptLargeblock):
for row in cryptLargeblock:
for item in row:
strangen += hex(item)[2:].zfill(2)
i += 1
outfile.write(strangen)
outfile.close()
print strangen
def fileDecrypt():
key = getKey("testKey")
file = open("decrypted_file","wb")
decryptBlock = []
decString = ""
eblock = getDecryptBlock("encrypted_file")
for i in range(len(eblock)):
decryptBlock.append(decrypt(eblock[i],key))
for row in decryptBlock:
for item in row:
decString += chr(item)
file.write(decString)
file.close()
print decString
if mode == "encrypt" or mode == "e":
fileEncrypt()
elif mode == "decrypt" or mode == "d":
fileDecrypt()