def unpad(bytestring, k=16):
    """
    Remove the PKCS#7 padding from a text bytestring.
    """
    val = bytestring[-1]
    if val > k:
        raise ValueError('Input is not padded or padding is corrupt')
    l = len(bytestring) - val
    return bytestring[:l]
