code: def strip_pkcs7_padding(m, block_size):
      
      if len(m) < block_size or len(m) % block_size != 0:
          raise BadPaddingException("Unable to strip padding: invalid message length")
  
      m = bytearray(m) # py2/3 compatibility: always returns individual indexed elements as ints
      last_byte = m[-1]
      # the <last_byte> bytes of m must all have value <last_byte>, otherwise something's wrong
      if (last_byte <= 0 or last_byte > block_size) or (m[-last_byte:] != bytearray([last_byte])*last_byte):
          raise BadPaddingException("Unable to strip padding: invalid padding found")
  
      return bytes(m[:-last_byte])
docs: Same as PKCS#5 padding, except generalized to block sizes other than 8.