code: def tripledes_cbc_pkcs5_encrypt(key, data, iv):
      
  
      if len(key) != 16 and len(key) != 24:
          raise ValueError(pretty_message(
              '''
              key must be 16 bytes (2 key) or 24 bytes (3 key) long - is %s
              ''',
              len(key)
          ))
  
      if not iv:
          iv = rand_bytes(8)
      elif len(iv) != 8:
          raise ValueError(pretty_message(
              '''
              iv must be 8 bytes long - is %s
              ''',
              len(iv)
          ))
  
      cipher = 'tripledes_3key'
      if len(key) == 16:
          cipher = 'tripledes_2key'
  
      return (iv, _encrypt(cipher, key, data, iv, True))
docs: 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)