예제 #1
0
    def decrypt(self, chiperByte, length):

        #transform into bit matrix
        chiperBit = Block(chiperByte, Block.BYTE)

        if (self.firstDecrypt):
            decrypted = self.chiperEngine.decrypt(chiperBit.bit)
            blockBit = Block((decrypted[0],decrypted[1], length), Block.BIT)
            blockByte = blockBit.byte[:length]
            self.firstDecrypt = False
        else:
            decrypted = self.chiperEngine.decrypt(chiperBit.bit)
            tk = Toolkit()
            decrypted = (tk.xorFunction(decrypted[0], self.prevChiper[0]), tk.xorFunction(decrypted[1], self.prevChiper[1]))
            blockBit = Block((decrypted[0], decrypted[1], length), Block.BIT)
            blockByte = blockBit.byte[:length]

        self.prevChiper = chiperBit.bit

        return blockByte, length
예제 #2
0
 def decrypt(self, blockByte, length):
     self.initQueue()
     chiperBit = Block(blockByte, Block.BYTE)
     decrypted = self.chiperEngine.decrypt(self.queue)
     tk = Toolkit()
     input = (tk.xorFunction(chiperBit.bit[0], decrypted[0]),
              tk.xorFunction(chiperBit.bit[1], decrypted[1]))
     blockBit = Block((input[0], input[1], 16), Block.BIT)
     blockByte = blockBit.byte
     self.queue = blockByte
     return blockByte[:length], length
예제 #3
0
    def encrypt(self, blockByte):
        length = len(blockByte)

        #assertion
        if length > 16:
            print("KABOOOMM!!!! Block too big")

        #transform into bit matrix
        blockBit = Block(blockByte, Block.BYTE)
        if (self.firstEncrypt):
            encrypted = self.chiperEngine.encrypt(blockBit.bit)
            chiperBit = Block((encrypted[0],encrypted[1],16), Block.BIT)
            chiperByte = chiperBit.byte
            self.firstEncrypt = False
        else:
            tk = Toolkit()
            input = (tk.xorFunction(blockBit.bit[0], self.prevChiper[0]), tk.xorFunction(blockBit.bit[1], self.prevChiper[1]))
            encrypted = self.chiperEngine.encrypt(input)
            chiperBit = Block((encrypted[0], encrypted[1], 16), Block.BIT)
            chiperByte = chiperBit.byte

        self.prevChiper = encrypted

        return chiperByte, length
예제 #4
0
    def encrypt(self, blockByte):
        self.initQueue()
        length = len(blockByte)

        #assertion
        if length > 16:
            print("KABOOOMM!!!! Block too big")
        blockBit = Block(blockByte, Block.BYTE)
        encrypted = self.chiperEngine.encrypt(self.queue)
        tk = Toolkit()
        input = (tk.xorFunction(blockBit.bit[0], encrypted[0]),
                 tk.xorFunction(blockBit.bit[1], encrypted[1]))
        chiperBit = Block((input[0], input[1], 16), Block.BIT)
        chiperByte = chiperBit.byte

        self.queue = chiperByte
        return chiperByte, length