def pad_data(data, pad_amount, pad_value=b"\x00", start_at=0):
    """ Pad a piece of data according to the padding value and returns the
    result. Use start_at to specify an offset at the starting point. """
    end_position = len(data) + start_at
    if end_position % pad_amount != 0:
        pad_size = pad_amount - (end_position % pad_amount)
        data += pad_value * pad_size
    return data