def decrypter():
    tools.empty_folder('files')
    key_1 = b""
    list_directory = tools.list_dir('key')
    filename = './key/' + list_directory[0]
    public_key = open(filename, "rb")
    for line in public_key:
        key_1 = key_1 + line
    public_key.close()
    secret_information = Algo1(key_1)
    list_information = secret_information.split(b':::::')
    key_1_1 = list_information[0]
    key_1_2 = list_information[1]
    key_2 = list_information[2]
    key_3 = list_information[3]
    key_4 = list_information[4]
    nonce12 = list_information[5]
    nonce13 = list_information[6]
    files = sorted(tools.list_dir('encrypted'))
    for index in range(0, len(files)):
        if index % 4 == 0:
            Algo1_extented(files[index], key_1_1, key_1_2)
        elif index % 4 == 1:
            Algo2(files[index], key_2, nonce12)
        elif index % 4 == 2:
            Algo3(files[index], key_3, nonce12)
        else:
            Algo4(files[index], key_4, nonce13)
def decrypter(Fname):
	tools.empty_folder('files')
	tools.empty_folder('./key_pem')
	list_directory = tools.list_dir('key')
	filename = './key/' + list_directory[0]
	in_f = filename
	out_f = "./key_pem/" + Fname +".pem"
	in_img = cv2.imread(in_f)
	steg = Steganography(in_img)
	key_1 = steg.decode_binary()

	secret_information = Algo1(key_1, Fname)
	list_information = secret_information.split(':::::')
	key_1_1 = list_information[0]
	key_1_2 = list_information[1]
	key_2 = list_information[2]
	key_3 = list_information[3]
	key_4 = list_information[4]
	nonce12 = list_information[5]
	nonce13 = list_information[6]
	files = sorted(tools.list_dir('./encrypted/' + Fname + '/files'))
	for index in range(0,len(files)):
		if index%4 == 0:
			Also1_RSA(files[index],key_1_1,key_1_2, Fname)
		elif index%4 == 1:
			Also2_TrippleDES(files[index],key_2,nonce12, Fname)
		elif index%4 == 2:
			Algo3(files[index],key_3,nonce12, Fname)
		else:
			Algo4(files[index],key_4,nonce13, Fname)
Beispiel #3
0
def encrypter():
    tools.empty_folder('key')
    tools.empty_folder('encrypted')
    key_1 = Fernet.generate_key()
    key_1_1 = Fernet.generate_key()
    key_1_2 = Fernet.generate_key()
    key_2 = ChaCha20Poly1305.generate_key()
    key_3 = AESGCM.generate_key(bit_length=128)
    key_4 = AESCCM.generate_key(bit_length=128)
    nonce13 = os.urandom(13)
    nonce12 = os.urandom(12)
    files = sorted(tools.list_dir('files'))
    for index in range(0, len(files)):
        if index % 4 == 0:
            Algo1_extented(files[index], key_1_1, key_1_2)
        elif index % 4 == 1:
            Algo2(files[index], key_2, nonce12)
        elif index % 4 == 2:
            Algo3(files[index], key_3, nonce12)
        else:
            Algo4(files[index], key_4, nonce13)
    secret_information = (key_1_1) + ":::::" + (key_1_2) + ":::::" + (
        key_2) + ":::::" + (key_3) + ":::::" + (key_4) + ":::::" + (
            nonce12) + ":::::" + (nonce13)
    Algo1(secret_information, key_1)
    public_key = open("./key/Taale_Ki_Chabhi.pem", "wb")
    public_key.write(key_1)
    public_key.close()
    tools.empty_folder('files')
def divide():
    tools.empty_folder('files')
    tools.empty_folder('raw_data')
    FILE = tools.list_dir('uploads')
    FILE = './uploads/' + FILE[0]

    MAX = 1024 * 32  # 1	MB	-	max chapter size
    BUF = 50 * 1024 * 1024 * 1024  # 50GB	-	memory buffer size

    chapters = 0
    uglybuf = ''
    meta_data = open('raw_data/meta_data.txt', 'w')
    file__name = FILE.split('/')
    file__name = file__name[-1]
    print(file__name)
    meta_data.write("File_Name=%s\n" % (file__name))
    with open(FILE, 'rb') as src:
        while True:
            target_file = open('files/SECRET' + '%07d' % chapters, 'wb')
            written = 0
            while written < MAX:
                if len(uglybuf) > 0:
                    target_file.write(uglybuf)
                target_file.write(src.read(min(BUF, MAX - written)))
                written += min(BUF, MAX - written)
                uglybuf = src.read(1)
                if len(uglybuf) == 0:
                    break
            target_file.close()
            if len(uglybuf) == 0:
                break
            chapters += 1
    meta_data.write("chapters=%d" % (chapters + 1))
    meta_data.close()
Beispiel #5
0
def restore(Fname):
	tools.empty_folder('restored_file')

	chapters = 0

	meta_data = open("./encrypted/" + Fname +'/raw_data/meta_data.txt','r')
	meta_info = []
	for row in meta_data:
		temp = row.split('\n')
		temp = temp[0]
		temp = temp.split('=')
		meta_info.append(temp[1])
	address = 'restored_file/' + meta_info[0]

	list_of_files = sorted(tools.list_dir('files'))

	with open(address,'wb') as writer:
		for file in list_of_files:
			path = 'files/' + file
			with open(path,'rb') as reader:
				for line in reader:
					writer.write(line)
				reader.close()
		writer.close()

	tools.empty_folder('files')
def return_file():
	list_directory = tools.list_dir('restored_file')
	filename = './restored_file/' + list_directory[0]
	print ("****************************************")
	print (list_directory[0])
	print ("****************************************")
	return send_file(filename, attachment_filename=list_directory[0], as_attachment=True)
def encrypter(fname):
	tools.empty_folder('./encrypted/' + fname + '/files/' )
	tools.empty_folder('./key/')
	key_1 = Fernet.generate_key()
	key_1_1 = Fernet.generate_key()
	key_1_2 = Fernet.generate_key()
	key_2 = ChaCha20Poly1305.generate_key()
	key_3 = AESGCM.generate_key(bit_length=128)
	key_4 = AESCCM.generate_key(bit_length=128)
	nonce13 = os.urandom(13)
	nonce12 = os.urandom(12)
	files = sorted(tools.list_dir('files'))
	for index in range(0,len(files)):
		if index%4 == 0:
			Algo1_extented(files[index],key_1_1,key_1_2, fname)
		elif index%4 == 1:
			Algo2(files[index],key_2,nonce12, fname)
		elif index%4 == 2:
			Algo3(files[index],key_3,nonce12, fname)
		else:
			Algo4(files[index],key_4,nonce13, fname)
	secret_information = (key_1_1)+":::::"+(key_1_2)+":::::"+(key_2)+":::::"+(key_3)+":::::"+(key_4)+":::::"+(nonce12)+":::::"+(nonce13)
	Algo1(secret_information,key_1, fname)

	# Static path to the image file for Steganography
	in_f = "./static/png.png"
	#out_f = './encrypted/' + fname + '/key/'  + fname + '.png'
	out_f = './key/'  + fname + '.png'
	in_img = cv2.imread(in_f)
	steg = Steganography(in_img)

	res = steg.encode_binary(key_1)
	cv2.imwrite(out_f, res)

	tools.empty_folder('files')
Beispiel #8
0
def divide():
    '''
	Splits uploaded binary files into chapters .000, .001,
	then on chapters we will do individually encryption.
	'''
    tools.empty_folder('files')
    tools.empty_folder('raw_data')
    FILE = tools.list_dir('uploads')
    FILE = './uploads/' + FILE[0]

    MAX = 1024 * 32  # 1	MB	-	max chapter size
    BUF = 50 * 1024 * 1024 * 1024  # 50GB	-	memory buffer size

    chapters = 0
    buf = ''
    meta_data = open('raw_data/meta_data.txt', 'w')
    file__name = FILE.split('/')
    file__name = file__name[-1]
    meta_data.write("File_Name=%s\n" % (file__name))
    with open(FILE, 'rb') as src:
        while True:
            target_file = open('files/SECRET' + '%07d' % chapters, 'wb')
            written = 0
            while written < MAX:
                if len(buf) > 0:
                    target_file.write(buf)
                target_file.write(src.read(min(BUF, MAX - written)))
                written += min(BUF, MAX - written)
                buf = src.read(1)
                if len(buf) == 0:
                    break
            target_file.close()
            if len(buf) == 0:
                break
            chapters += 1
    meta_data.write("chapters=%d" % (chapters + 1))
    meta_data.close()
def return_key():
    list_directory = tools.list_dir('key')
    filename = './key/' + list_directory[0]
    return send_file(filename, attachment_filename='My_Key.pem')
def return_key():
    list_directory = tools.list_dir('key')
    filename = './key/' + list_directory[0]

    return send_file(filename, as_attachment=True)