def pkcs7_pad(data, block_size=16):
    """Calculate and append pkcs7 padding. Block size can be defined dynamically."""
    last_block = data[block_size*(len(data)/block_size):]
    if not last_block:
        return data + chr(block_size)*block_size
    rem = block_size - len(last_block)
    return data + chr(rem)*rem