def tripledes_cbc_pkcs5_encrypt(key, data, iv):
if len(key) != <NUM_LIT:16> and len(key) != <NUM_LIT>:<EOL><INDENT>raise ValueError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>len(key)<EOL>))<EOL><DEDENT>if not iv:<EOL><INDENT>iv = rand_bytes(<NUM_LIT:8>)<EOL><DEDENT>elif len(iv) != <NUM_LIT:8>:<EOL><INDENT>raise ValueError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>len(iv)<EOL>))<EOL><DEDENT>cipher = '<STR_LIT>'<EOL>if len(key) == <NUM_LIT:16>:<EOL><INDENT>cipher = '<STR_LIT>'<EOL><DEDENT>return (iv, _encrypt(cipher, key, data, iv, True))<EOL>
Encrypts plaintext using 3DES in either 2 or 3 key mode

:param key:
    The encryption key - a byte string 16 or 24 bytes long (2 or 3 key mode)

:param data:
    The plaintext - a byte string

:param iv:
    The 8-byte initialization vector to use - a byte string - set as None
    to generate an appropriate one

:raises:
    ValueError - when any of the parameters contain an invalid value
    TypeError - when any of the parameters are of the wrong type
    OSError - when an error is returned by the OS crypto library

:return:
    A tuple of two byte strings (iv, ciphertext)