Пример #1
0
    def Exsend_(self):
        Send_().send_all()
        r_sc = 406572794028345823020817876817526759659544524999
        r_sc = (bytes(str(r_sc), 'utf-8'))
        localtime = time.asctime( time.localtime(time.time()) )
        localtime = (bytes(str(localtime), 'utf-8'))

        z_sc = hashlib.sha256()
        z_sc.update(r_sc)
        z_sc.update(localtime)
        z_sc.update(bytes(str(My_ID), 'utf-8'))
        z_sc = int(z_sc.hexdigest(), 16)
        K_2c = z_sc * p
        K_1c = (K_2c.x * d_c) * P_b
        X_K1c = (bytes(str(K_1c.x), 'utf-8'))
        Y_K2c = (bytes(str(K_2c.y), 'utf-8'))

                                                  #encryption
        key_c = X_K1c[:16] # Symmetric Key
        aese_c = aes.AESModeOfOperationOFB(key_c, iv_c)
        text = zipfile.ZipFile(temp_ + "source.zip", mode="w")
        n = len(a)
        i = 0
        while True:
            if i < len(a):
                text.write(a[i])
                i += 1
            else:
                break
        text.close()
        text = open(temp_ + "source.zip", "rb")
        text = text.read()
        h_c = hashlib.sha256()
        h_c.update(text)
        h_c.update(Y_K2c)
        h_c = int(h_c.hexdigest(), 16)
        C = aese_c.encrypt(text)

        S = (z_sc - (h_c * d_c))%q
        R = h_c * P_c

        Dict = {'s':S, 'r':str(R), 'c':C}

        if self.ids.Steganography.state == "down":
            f = open(temp_+ "crytp.txt", "w")
            f.write(str(Dict))
            f.close()

            TextToHide = open(temp_+ "crytp.txt", "r").read()
            ImageFile = image_file_path
            StegImageFile = (output_file_path + ".bmp")
            LSBEncrypter().hide_(TextToHide, ImageFile, StegImageFile)
        else:
            f = open(output_file_path + ".txt", "w")
            f.write(str(Dict))
            f.close()
        shutil.rmtree(temp_, ignore_errors=True)
        self.ids.Steganography.state = "normal"
Пример #2
0
    def Exreceive_(self):

        Receive_().receive_all()
        # if os.path.exists(temp_) == True:
        #     pass
        # else: temp_

        if R_path.endswith('.txt'):

            f = open(R_path, "r")
            my_dict = eval(f.read())
        else:
            im1 = Image.open(R_path)
            text = stepic.decode(im1)
            rec_ = open(temp_ + "crytp.txt", "wb")
            rec_.write(bytearray(map(ord, text)))
            rec_.close()
            f = open(temp_ + "crytp.txt", "r")
            my_dict = eval(f.read())

        R = my_dict['r']
        S = my_dict['s']
        Cr = my_dict['c']
        f.close()

        R = R.split()
        r_x = int(R[1], base=16)
        r_y = int(R[3], base=16)
        R = curves.Point(r_x, r_y, cv)
        # Bank
        K_2b = (S * p) + R
        Y_K2b = (bytes(str(K_2b.y), 'utf-8'))

        K_1b = (K_2b.x * d_b) * P_c
        X_K1b = (bytes(str(K_1b.x), 'utf-8'))
        key_b = X_K1b[:16]  # Symmetric Key
        iv_b = "9B7D2C34A366BF89"
        aesd_b = aes.AESModeOfOperationOFB(key_b, iv_b)
        decrypted_b = aesd_b.decrypt(Cr)
        plaintext = open(temp_ + "plain.zip", "wb")
        plaintext.write(decrypted_b)
        plaintext.close()
        plaintext = open(temp_ + "plain.zip", "rb")
        plaintext = plaintext.read()

        h_b = hashlib.sha256()
        h_b.update(plaintext)
        h_b.update(Y_K2b)
        h_b = int(h_b.hexdigest(), 16)
        R_b = h_b * P_c
        print(temp_)
        if R == R_b:
            shutil.move(temp_ + "plain.zip", output_file_path + ".zip")
            Factory.RWin().open()
        else:
            Factory.RDefeat().open()
        shutil.rmtree(temp_, ignore_errors=True)
Пример #3
0
    def Exreceive_(self):

        Receive_().receive_all()

        f = open(R_path, "r")
        my_dict = eval(f.read())

        R = my_dict['r']
        S = my_dict['s']
        Cr = my_dict['c']
        f.close()
        print(temp_)
        shutil.rmtree(temp_, ignore_errors=True)
        R = R.split()
        r_x = int(R[1], base=16)
        r_y = int(R[3], base=16)
        R = curves.Point(r_x, r_y, cv)
        # Bank
        K_2b = (S * p) + R
        Y_K2b = (bytes(str(K_2b.y), 'utf-8'))

        K_1b = (K_2b.x * d_b) * P_c
        X_K1b = (bytes(str(K_1b.x), 'utf-8'))
        key_b = X_K1b[:16]  # Symmetric Key
        iv_b = "9B7D2C34A366BF89"
        aesd_b = aes.AESModeOfOperationOFB(key_b, iv_b)
        decrypted_b = aesd_b.decrypt(Cr)
        plaintext = open(output_file_path + ".zip", "wb")
        plaintext.write(decrypted_b)
        plaintext.close()
        plaintext = open(output_file_path + ".zip", "rb")
        plaintext = plaintext.read()

        h_b = hashlib.sha256()
        h_b.update(plaintext)
        h_b.update(Y_K2b)
        h_b = int(h_b.hexdigest(), 16)
        R_b = h_b * P_c

        if R == R_b:
            Factory.RWin().open()
        else:
            Factory.RDefeat().open()