'encrypt(data, [pad], [padmode]) -> bytes
data : bytes to be encrypted
pad  : Optional argument for encryption padding. Must only be one byte
padmode : Optional argument for overriding the padding mode.
The data must be a multiple of 8 bytes and will be encrypted
with the already specified key. Data does not have to be a
multiple of 8 bytes if the padding character is supplied, or
the padmode is set to PAD_PKCS5, as bytes will then added to
ensure the be padded data is a multiple of 8 bytes.'

def encrypt(self, data, pad=None, padmode=None):

    ENCRYPT = des.ENCRYPT
    DECRYPT = des.DECRYPT
    data = self._guardAgainstUnicode(data)
    if (pad is not None):
        pad = self._guardAgainstUnicode(pad)
    data = self._padData(data, pad, padmode)
    if (self.getMode() == CBC):
        self.__key1.setIV(self.getIV())
        self.__key2.setIV(self.getIV())
        self.__key3.setIV(self.getIV())
        i = 0
        result = []
        while (i < len(data)):
            block = self.__key1.crypt(data[i:(i + 8)], ENCRYPT)
            block = self.__key2.crypt(block, DECRYPT)
            block = self.__key3.crypt(block, ENCRYPT)
            self.__key1.setIV(block)
            self.__key2.setIV(block)
            self.__key3.setIV(block)
            result.append(block)
            i += 8
        if (_pythonMajorVersion < 3):
            return ''.join(result)
        else:
            return bytes.fromhex('').join(result)
    else:
        data = self.__key1.crypt(data, ENCRYPT)
        data = self.__key2.crypt(data, DECRYPT)
        return self.__key3.crypt(data, ENCRYPT)
