def decrypt(filename, directory, public_key, private_key): key = DH.generate_secret(long(private_key), long(public_key)) str = key.encode('hex') key = str[0:32] file_obj = open(filename, "r") msg = file_obj.read() text = ENCDEC.AESCipher(key).decrypt(msg) outputFilename = os.path.join(directory, "DecodedFile.txt") file_obj = open(outputFilename, "w") file_obj.write(text) os.remove(filename) os.system("xdg-open " + directory)
def encrypt(filename, directory, public_key, private_key): key = DH.generate_secret(long(private_key), long(public_key)) str = key.encode('hex') key = str[0:32] file_obj = open(filename, "r") t = time.time() msg1 = ENCDEC.AESCipher(key).encrypt(file_obj.read()) s = time.time() outputFilename = os.path.join(directory, key[16:] + ".txt") file_obj = open(outputFilename, 'w') file_obj.write(msg1) os.remove(filename) os.system("xdg-open " + directory)
def decrypt(filename,directory,public_key,private_key): key = DH.generate_secret(int(private_key), int(public_key)) str = key.encode('utf-8').hex() key = str[0:32] file_obj = open(filename,"r") msg = file_obj.read() #list = msg.split('\n') #msg1 = list[0] #msg2 = list[2] text = ENCDEC.AESCipher(key).decrypt(msg) #msg2 = ENCDEC.AESCipher(key).decrypt(msg2) #temp = [] #temp.append(unicodedata.normalize('NFKD',msg1).encode('ascii','ignore')) #temp.append(list[1]) #text = ENCDEC.shamirs_join(temp,unicodedata.normalize('NFKD',msg2).encode('ascii','ignore')) #outputFilename = os.path.join(directory,"DecodedFile.txt") #file_obj = open(outputFilename,"w") #file_obj.write(text) os.remove(filename)
def encrypt(filename,directory,public_key,private_key): key = DH.generate_secret(int(private_key), int(public_key)) str = key.encode('utf-8').hex() key = str[0:32] file_obj = open(filename,"r") t = time.time() #list,str = ENCDEC.shamirs_split(file_obj) msg1 = ENCDEC.AESCipher(key).encrypt(file_obj.read()) #msg2 = ENCDEC.AESCipher(key).encrypt(str) s = time.time() #Exchange this with public key outputFilename = os.path.join(directory,key[16:]+".txt") file_obj = open(outputFilename,'w') file_obj.write(msg1) #file_obj.write('\n') #file_obj.write(list[1]) #file_obj.write('\n') #file_obj.write(msg2) os.remove(filename)