def tripledes_cbc_pkcs5_decrypt(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 len(iv) != <NUM_LIT:8>:<EOL><INDENT>raise ValueError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>len(iv)<EOL>))<EOL><DEDENT>if len(key) == <NUM_LIT:16>:<EOL><INDENT>key = key + key[<NUM_LIT:0>:<NUM_LIT:8>]<EOL><DEDENT>return _decrypt(Security.kSecAttrKeyType3DES, key, data, iv, Security.kSecPaddingPKCS5Key)<EOL>
Decrypts 3DES ciphertext 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 ciphertext - a byte string

:param iv:
    The initialization vector used for encryption - a byte string

: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 byte string of the plaintext