def crypt(self, data, crypt_type):
<EOL>if not data:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>if len(data) % self.block_size != <NUM_LIT:0>:<EOL><INDENT>if crypt_type == des.DECRYPT: <EOL><INDENT>raise ValueError("<STR_LIT>" + str(self.block_size) + "<STR_LIT>" + data + "<STR_LIT:.>")<EOL><DEDENT>if not self.getPadding():<EOL><INDENT>raise ValueError("<STR_LIT>" + str(self.block_size) + "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>data += (self.block_size - (len(data) % self.block_size)) * self.getPadding()<EOL><DEDENT><DEDENT>if self.getMode() == CBC:<EOL><INDENT>if self.getIV():<EOL><INDENT>iv = self.__String_to_BitList(self.getIV())<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>i = <NUM_LIT:0><EOL>result = []<EOL>while i < len(data):<EOL><INDENT>block = self.__String_to_BitList(data[i:i+<NUM_LIT:8>])<EOL>if self.getMode() == CBC:<EOL><INDENT>if crypt_type == des.ENCRYPT:<EOL><INDENT>block = list(map(lambda x, y: x ^ y, block, iv))<EOL><DEDENT>processed_block = self.__des_crypt(block, crypt_type)<EOL>if crypt_type == des.DECRYPT:<EOL><INDENT>processed_block = list(map(lambda x, y: x ^ y, processed_block, iv))<EOL>iv = block<EOL><DEDENT>else:<EOL><INDENT>iv = processed_block<EOL><DEDENT><DEDENT>else:<EOL><INDENT>processed_block = self.__des_crypt(block, crypt_type)<EOL><DEDENT>result.append(self.__BitList_to_String(processed_block))<EOL>i += <NUM_LIT:8><EOL><DEDENT>if _pythonMajorVersion < <NUM_LIT:3>:<EOL><INDENT>return '<STR_LIT>'.join(result)<EOL><DEDENT>else:<EOL><INDENT>return bytes.fromhex('<STR_LIT>').join(result)<EOL><DEDENT>
Crypt the data in blocks, running it through des_crypt()