def main(): global image global i j = 0 ## still_image is for the camera module. Uncomment only if u have an camera module #still_image() file_list = os.listdir() for i in range(len(file_list)): if ('.jpg' in file_list[i]): filename = file_list[i] #Load the photo into the face recognition algorithm and obtain face_locations image = face_recognition.load_image_file(filename) face_locations = face_recognition.face_locations(image) #Mask the face with random image image = masking(face_locations) SaveBlurring() #Generate key key = AEAD.generate_key() #Encrypt image and face count faceCountEncrypted = number_encryption(key) imageEncrypted = image_encryption(key) writeBinaryFile(faceCountEncrypted, 'faceCount{}'.format(j)) writeBinaryFile(imageEncrypted, 'image{}'.format(j)) # Assume key and assoicated_data already known at the server side writeBinaryFile(key, 'key{}'.format(j)) writeBinaryFile(associated_data.encode(), 'associated_data{}'.format(j)) j = j + 1
# -*- coding: utf-8 -*- from aead import AEAD sifreleyici = AEAD(AEAD.generate_key()) # 100 defa hashleme metedu def getHash(key): hashli_metin = "" for x in range(0, 100): hashli_metin = hash(key) return hashli_metin # girdi.txt dosyasinin ve key.txt dosyalarinin okunmasi ve haslenip cikti.txt icine yazilmasi def girdiyi_sifrele(): with open("girdi.txt", "r") as fileReadInput: with open("key.txt", "r") as fileReadKey: with open("cikti.txt", "a") as fileWriteOutput: key = fileReadKey.readline().strip() for line in fileReadInput.readlines(): fileWriteOutput.write( sifreleyici.encrypt(line.strip(), key) + "||" + str(hash(line.strip())) + "||" + str(getHash(key)) + "\n") with open("cikti.txt", "w") as fileReadd: print "" # cikti.txt nin icindeki veriler okunup ayristirildiktan sonra butunluk testinin yapilmasi def ciktiyi_coz():
def test_round_trip_encrypt_decrypt(plaintext, associated_data): cryptor = AEAD(AEAD.generate_key()) ct = cryptor.encrypt(plaintext, associated_data) assert plaintext == cryptor.decrypt(ct, associated_data)
# Practice aead encryption from aead import AEAD import sys file = sys.argv[1] print('Name of the file you want to encrypt is ', file) flag = True cryptor = AEAD(AEAD.generate_key()) while(flag): response = input('Enter 1 to encrypt file, 2 to decrypt file, and 3 to exit program: ') if response == "1": with open('spring.txt', 'r') as myfile: data = myfile.read() myfile.close() bytesData = data.encode() encrypted = cryptor.encrypt(bytesData, b"AuthenticatedData") print('encrypted: ', encrypted) with open('spring.txt', 'w') as the_file: the_file.write(encrypted.decode("utf-8")) the_file.close() elif response == "2": with open('spring.txt', 'r') as myfile: data = myfile.read() myfile.close()
def test_invalid_signature(): aead = AEAD(AEAD.generate_key()) ct = aead.encrypt(b"Hello, World", b"Goodbye, World!") with pytest.raises(ValueError): aead.decrypt(ct, b"foobar")
def test_round_trip_encrypt_decrypt(): aead = AEAD(AEAD.generate_key()) ct = aead.encrypt(b"Hello, World!", b"Goodbye, World!") assert aead.decrypt(ct, b"Goodbye, World!") == b"Hello, World!"
def generate_key(): #generate key key = AEAD.generate_key() return key